How to Retrieve a Directory Recursively by FTP Alternatively

  • by

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 "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 a indirect way, which is as simple as possible.

1. Zip you directory recursively on server side.

$ cd ~/Workspace
$ zip -r AllScripts
  adding: AllScripts/ (stored 0%)
  adding: AllScripts/ (deflated 73%)
  adding: AllScripts/ (deflated 79%)
  adding: AllScripts/ (deflated 76%)

2. Connect as a FTP client to get the zip file.

D:\> ftp
Connected to
220 orcl FTP server ready.
User ( oracle
331 Password required for oracle.
230 User oracle logged in.
ftp> cd /home/oracle/Workspace
250 CWD command successful.
ftp> binary
200 Type set to I.
ftp> get
200 PORT command successful.
150 Binary data connection for (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.

3. 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 *