C Ftp Download All Files

While writing the 'Core FTP LE Product Spotlight' blog post, I discovered a new way to transfer files using FTP. It led me to wonder how many other people were unaware of the two-plus ways to transfer files via FTP using only the tools provided in Windows.

I will briefly discuss each method using Windows 7 in the examples below. These instructions will also work in Windows Vista. Each method uses a different component of Windows to initiate the transfer:

Go through your code and keep pulling out all of the methods aiming to get each one to do a single thing. For example, I'd probably pull out another method from the above (ListDirectories) called CreateListDirectoriesRequest and have that create the WebRequest. Other thoughts. Ftp or ftp never FTP in names.

  • Internet Explorer 8
  • Windows Explorer
  • DOS command line
Download file from ftp site

Method One - Internet Explorer 8

Everyone who browses the Internet should be familiar with the addresses that are typed in the browser address bar to access a Web site, for example:

The address for FTP access is similar:

Type a public FTP site address like Microsoft's (Figure A) in the address bar and press [Return], and you can find knowledge base articles, patches, updated drivers, utilities, and documentation — though the information there is now dated. View the readme.txt files at the site for more information. If you successfully connect, you should see the root directory. You can click on a directory to access sub-directories and files. Download a file by right-clicking on the file and selecting Save Target As...

This blog post is also available in PDF format in a TechRepublic download.

Figure A

Here is FTP from Internet Explorer 8.
Note: Tools | Internet Options | Advanced tab | Enable FTP folder view (outside of Internet Explorer) and the Use Passive FTP (for firewall and DSL modem compatibility) options under Browsing should be checked by default. If not, enable these options.Non-public sites require a user name and password (Figure B). This is convenient for listing the files on the remote FTP server, but if you are using IE 7 or IE 8 you will need to launch Windows Explorer to transfer files. (See Figures C, D, E, and F.)

Figure B

Non-public sites require a user name and password.

Figure C

Select Page | Open FTP Site in Windows Explorer to open Windows Explorer. Alternatively, you can select View | Open FTP Site in Windows Explorer from the menu.

Figure D

Click Allow when the Internet Explorer Security window opens.

Figure E

Enter your user name and password and select Log On to connect using Windows Explorer.

Figure F

If you connect successfully, you should be able to transfer files to and from the FTP server just as you would with any local drive.

Method Two - Windows Explorer

Method one is rather awkward. You can connect to the remote server directly in Windows Explorer (Figures G and H).

Figure G

Open Windows Explorer and type the FTP address in the address bar.

Figure H

Hit Return after typing the address, and you will be prompted for a user name and password.

But what if you routinely connect to a FTP server? You don't want to have to type the FTP address each time you want to connect. There are three ways to create a shortcut or link for quick access. First, connect to the FTP server in Windows Explorer.

Option one - Create a desktop shortcut

There are two ways to create a desktop shortcut for a file or folder for quick access:

  • Select the remote file or folder and press and hold down the [Ctrl][Shift] keys. Drag and drop the file or folder to the desktop.
  • Right-click on the remote file or folder and hold down the right mouse button. Drag and drop the file or folder to the desktop. Select Create Shortcuts Here.

Option two - Create a link under Favorites

There are two ways to create a link to a folder for quick access:

  • Drag and drop a remote folder to Favorites in the navigation pane.
  • Right-click on the remote folder and then hold down the right mouse button. Drag and drop the folder to Favorites in the navigation pane. Select Create Shortcuts Here.

Option three - Create a link under Computer

The Add Network Location Wizard will create a link under Computer in the navigation pane. Right-click on Computer in the navigation pane then select Add a Network Location to open the Add Network Location Wizard. For a complete step-by-step guide, please visit the associated TechRepublic Photo Gallery.

FTP folders in Windows Explorer

A Microsoft spokesperson sent me the following information about the features and limitations of FTP folders in Windows Explorer:

'FTP Folders work natively in the Windows Explorer and allow users to:

  • Browse them, in a limited way (no metadata or thumbnails)
  • Copy, move and delete files and folders
  • Create new folders
  • Search/filter the current view
  • Add to favorite links
  • Open Files using the Common File Dialog

Unsupported behavior:

  • You cannot copy or move files between folders on the server, only to and from your PC
  • There are no thumbnails, metadata or previews
  • You can only save to FTP folders using the Common File Dialog if the application supports opening from a virtual namespace (which is rare)
  • You cannot see Unicode file names
  • There are no secondary streams'

Method Three - DOS command line

The ftp.exe executable is a Windows utility that can be started from a command prompt window command line. You can manually transfer files using the FTP utility, but the power of this method is automation. It is a very convenient way to schedule and automate the regular transfer of files.

To view help for the FTP utility, open a command prompt window and type ftp -? [Return]at the command line. To view the commands available in FTP, type ftp [Return]to start the FTP utility and then type ? [Return]at the FTP prompt. Type bye [Return] at the FTP prompt to exit the FTP utility.

Download File From Ftp Site

You can create batch files and FTP scripts in order to automate the file transfer process. In the following examples, replace the italicized text with your unique host name, user name, password, local path, and remote server directory.

Editor's note: The following commands are examples. You will have to adjust drive letters and folders to match your system.

Transfer a single file

Type the following into Notepad and save as H:TransferTesttransfer.bat:

ftp -v -n -s:H:TransferTesttransfer.ftp

This is what the ftp command does:

  • ftp — Invoke FTP utility
  • -v — Suppress display of remote FTP server responses
  • -n — Suppress auto-login
  • -s: — Specifies the path including the name of the file containing FTP commands. Note: The path cannot contain spaces.

Type the following into Notepad and save as H:TransferTesttransfer.ftp:

open example.yourhostingsite.com

user yourusername

password

cd /public_ftp/test

put 'W:pecos-softwareworksshtmlchanges_to_the_windows7_taskbar_you_should_know_about.shtml'

bye

This is what the FTP commands do:

  • open — Open the remote FTP server
  • user — Log in using the user name
  • password — Log in using the user password
  • cd — Change to the specified remote directory where you want to upload the files, /public_ftp/test in this example
  • put — Upload the specified local file. The quotation marks are optional if there are no spaces in the path.
  • bye — Quit FTP session and exit FTP
HttpsTip: FTP commands can be abbreviated to three characters, so you may see scripts written with commands such as binary abbreviated to bin.Tip: Long path names can be time consuming to type and easy to mistype. You can simplify the process by using one of these methods:
  • Navigate to the file in Windows Explorer, right-click on any part of the breadcrumb style address in the address bar, and select Copy Address as Text. Paste the address into your FTP script file and add the file name.
  • The full path including the file name can be copied to the clipboard. Right-click on a file in Windows Explorer, select Properties, and click the Security tab. Select and copy the full path next to Object name: and paste it into your FTP script file.

Download Ftp Files Windows 10

From a command prompt, type H:TransferTesttransfer.bat

C Ftp Download All Files Download

or open the batch file to run it. You may see a Windows Security Alert (Figures I and J):

Figure I

Select the Public Networks option and click Allow Access.

Figure J

The put command uploads one file from the client to the server. If the file already exists on the remote server, it will be overwritten.

Use the get command to download one file from the server to the client.

Transferring multiple files

Type the following into Notepad and save as H:TransferTestmultiple_transfer.bat:

cd /D W:pecos-softwareworksshtml

ftp -v -n -s:H:TransferTestmultiple_transfer.ftp

Type the following into Notepad and save as H:TransferTestmultiple_transfer.ftp:

open example.yourhostingsite.com

user yourusername

password

cd /public_ftp/test

Files

prompt

mput 'changes_to_the_windows7_taskbar_you_should_know_about.shtml' 'a_case_of_maxtaken_identity.shtml'

lcd ProjectsPSWWVICPackage

binary

mput 'vista_image_capture_1_1_2.zip' 'vista_image_capture_1_2_0.zip'

C# Download File From Https

bye

This is what the FTP commands do:

  • open — Open the remote FTP server
  • user — Log in using the user name
  • password — Log in using the user password
  • cd — Change to the specified remote directory where you want to upload the files, /public_ftp/test in this example
  • prompt — Disable interactive prompting when uploading multiple files using the mput command
  • mput - Upload the specified local ASCII files. The quotation marks are optional if there are no spaces in the path.
  • lcd - Change to the specified local directory containing the files that will be transferred, ProjectsPSWWVICPackage in this example
  • binary — Switch to the binary transfer mode
  • mput — Upload the specified local binary files. The quotation marks are optional if there are no spaces in the path.
  • bye — Quit FTP session and exit FTP
From a command prompt, type H:TransferTestmultiple_transfer.bat or open the batch file to run it (Figure K).

Figure K

You can do multiple transfers.

Note that I used the cd change drive and directory command in the batch file and the lcd change local directory FTP command in the FTP script to simplify the mput commands so that the relative path could be used instead of the full path.

Tip: Spaces can be problematic. Use underscore characters instead of spaces when possible.

The mput command uploads multiple files from the client to the server. If the files already exist on the remote server, they will be overwritten.

Use the mget command to download multiple files from the server to the client.

There are other variations of this method, including creating one batch file. I'll leave it to you to explore them if you wish.

Transferring ASCII and binary files

FTP handles transfers of ASCII (text) files differently from binary files. By default, the Windows FTP utility transfers files using the ASCII mode. The single file example above transfers one ASCII file. The multiple file example transfers both ASCII and binary files. To avoid possible data corruption, use the right transfer mode.

Security issues

There is one obvious security issue. If you have your user ID and password in an unencrypted text file, it can be read by anyone with access to the computer, so you will want to encrypt the FTP script file. Search for encrypt in Windows Help and click the Encrypt or Decrypt a Folder or File item or view these Microsoft Web pages for how to encrypt your data with Windows 2000, Windows Server 2003, Windows XP, Windows Vista, or Windows 7. Wikipedia lists the Windows operating systems that support the Encrypting File System (EFS). You can also use a third-party application like TrueCrypt.

Potential firewall issues

If you receive a 425 Unable to build data connection: Connection timed out error the problem is likely with your firewall. The FTP utility does not support the passive transfer mode, and this can lead to firewall issues. I received this error using Comodo Firewall 4.0, and there are several workarounds that I can detail in the forum. If you are having this issue with your firewall, you will need to configure the firewall to allow access for the FTP utility.

The final word

Before you go looking for a third-party app, take a closer look at the tools provided in Windows. One of the above methods may be the perfect solution for your FTP needs.

Susan Harkins makes a good point in 'Recommend Clients Using FTP Switch to SSL or SSH' that sensitive or confidential data should not be sent using the FTP protocol.

Additional resources

Microsoft Windows Command-Line FTP Command List - nsftools.com

Active FTP vs. Passive FTP, a Definitive Explanation - Slacksite.com

ASCII or Binary? Which Files Are Which - Webweaver

Stay on top of the latest XP tips and tricks with TechRepublic's Windows XP newsletter, delivered every Thursday. Automatically sign up today!

Author's Note

I would like to thank Microsoft for their help with this article.