65.9K
CodeProject is changing. Read more.
Home

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

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (1 vote)

May 15, 2019

CPOL

1 min read

viewsIcon

6575

How to use wget to download files recursively from a FTP server

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