Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / operating-systems / Windows

Downloading All the Files and Folders from a FTP Server Recursively using a Batch File and wget

4.00/5 (1 vote)
15 May 2019CPOL1 min read 6.6K  
How to use wget to download files recursively from a FTP server

This article appears in the Third Party Products and Tools section. Articles in this section are for the members only and must not be used to promote or advertise products in any way, shape or form. Please report any spam or advertising.

Introduction

I needed to download all the files in a robot controller in order to back up them into a server.

That robot controller offered only FTP connection to get access to those files.

From a Windows 7 computer, I needed to automate the download of all those files.

The FTP tools that come preinstalled with Windows are easy to use, but don't offer any option to recursively download files.

In order to be able to do that, you should create a script that would list the files and folders and then process them all.

Background

  • Download files from the Internet
  • Know usernames and passwords from the FTP server
  • Basic file editing

Using the Code

The first step is to download the wget tool from its site: http://gnuwin32.sourceforge.net/packages/wget.htm

Once you have the tool in your computer, you'll have to write a batch file with those contents:

c:\"program files (x86)"\GnuWin32\bin\wget 
--ftp-user=SERVER_USER_NAME--ftp-password=SERVER_USER_PASSWORD 
--recursive ftp://IP_ADDRESS_OF_YOUR_SERVER/ --directory-prefix="DESTINATION_PATH"

The path to the wget executable is given at the beginning.

The user name and password are given using the --ftp-user and --ftp-password arguments.

The --recursive parameter activates the ability to go deep up to 5 levels (unless you specify something different).

Then you specify your FTP server address, using the IP address or the name of the computer, and finally, you specify the folder where you want the files to be downloaded.

This small tip is a very simple thing, but can help many people who need to perform this kind of automation and to myself to remember what I did.

History

  • 15th May, 2019: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)