Click here to Skip to main content
15,885,890 members
Articles / Operating Systems / Windows
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
15 May 2019CPOL1 min read 6.2K   2   1
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)


Written By
Chief Technology Officer robotecnik
Spain Spain
I'm from Catalonia (in Spain) and a specialist in CNC, PLC, robotics and automation in general.

From 1998 I've been developing software applications for the automation market.

I'm using different technologies in each case to get the proper result, fieldbus communications, special electronics, special laser sensors, artificial vision, robot arms, CNC applications, PLC's...

www.robotecnik.com[^] - robots, CNC and PLC programming

Comments and Discussions

 
GeneralMy vote of 4 Pin
Member 1236439016-May-19 2:38
Member 1236439016-May-19 2:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.