Skip to content
Home » Network » How to Retrieve a Directory Recursively by FTP Alternatively

How to Retrieve a Directory Recursively by FTP Alternatively

There is no direct FTP command that can recursively download a directory, so don't expect that you can do this operation in one or few ftp commands, if you have hundreds of files needed to be downloaded via ftp, you can choose one of the following solutions:

The first choice is to install a GUI FTP client tool to drag and drop a directory to achieve your work. The tool will retrieves all files under the directory for you. One of famous FTP GUI tools is Filezilla that is very easy to use.

But sometimes, you are not allowed to install any GUI tools or script-based utilities like command lftp to facilitate you to do it, there's only a very basic ftp for you to use. Even though, we can also get the same result in an indirect way, which is as simple as possible.

Zip you directory recursively on server side.

$ cd ~/Workspace
$ zip -r 20110408.zip AllScripts
  adding: AllScripts/ (stored 0%)
  adding: AllScripts/Scripts14.sh (deflated 73%)
  adding: AllScripts/Scripts27.sh (deflated 79%)
  adding: AllScripts/Scripts38.sh (deflated 76%)
...

Connect as a FTP client to get the zip file.

D:\> ftp ftp.example.com
Connected to ftp.example.com.
220 orcl FTP server ready.
User (ftp.example.com:(none)): oracle
331 Password required for oracle.
Password:
230 User oracle logged in.
ftp> cd /home/oracle/Workspace
250 CWD command successful.
ftp> binary
200 Type set to I.
ftp> get 20110408.zip
200 PORT command successful.
150 Binary data connection for 20110408.zip (435234551 bytes).
226 Binary Transfer complete.
ftp: 435234551 bytes received in 76.88Seconds 5528.2Kbytes/sec.
ftp> quit
221 Goodbye.

Note that, we set the transportation mode to binary to get a correct copy.

Unzip the zip file in client side.

You can unzip the file by any tool as you like. Now, we're done.

If you get the zip file with ASCII mode (the default mode) in FTP, you will get error like this when unzipping the file:

Unzip failed because the file downloaded in ASCII mode.
Unzip failed because the file downloaded in ASCII mode.

If you're in server-to-server mode and insist to use command line, you can install lftp to download a bunch of files with scripts. Please refer to the following post for more information: How to Use LFTP over SFTP Protocol.

Leave a Reply

Your email address will not be published. Required fields are marked *