The default command line ftp client in most UNIX distributions do not support recursive downloads, even though recursive downloads is a basic feature in most GUI based ftp clients. But if you do not have access to the X-Windows or GUI, there are alternative ways to achieve the same result from the command line.
Recursive FTP Download
One alternative method is to use the wget command.
1 2 |
ibrahim@anfield:~$ mkdir dnld ; cd dnld ibrahim@anfield:~/dnld$ wget --user=<span class="red">username</span> --password=<span class="red">password</span> ftp://ftpsite.com/directory/to/download/ |
If your wget client does not support the ‘–user’ and ‘–password’ arguments, you must modify the FTP URL to include the login details.
1 2 |
ibrahim@anfield:~$ mkdir dnld ; cd dnld ibrahim@anfield:~/dnld$ wget ftp://<span class="red">username</span>:<span class="red">password</span>@ftpsite.com/directory/to/download/ |
Another alternative method is to use the lftp command for the recursive FTP download. Login to the FTP site, change to the required remote directory and use the mirror option to start the recursive download.
1 2 3 4 5 6 |
ibrahim@anfield:~$ mkdir dnld ; cd dnld ibrahim@anfield:~/dnld$ lftp ftp://ftpsite.com/ <span class="orange">lftp ftpsite.com:~> </span>user <span class="red">username</span> Password: <span class="orange">lftp ftpsite.com:~> </span>cd /directory/to/download/ <span class="orange">lftp ftpsite.com:~/directory/to/download/> </span>mirror . |
Recursive FTP Upload
To perform a recursive FTP upload, lftp is the only option for now as wget does not allow FTP uploads.
The mirror -R option in lftp can be used for the upload.
1 2 3 4 5 6 |
ibrahim@anfield:~$ cd upld ibrahim@anfield:~/upld$ lftp ftp://ftpsite.com/ <span class="orange">lftp ftpsite.com:~> </span>user <span class="red">username</span> Password: <span class="orange">lftp ftpsite.com:~> </span>cd /directory/to/upload/ <span class="orange">lftp ftpsite.com:~/directory/to/upload/> </span>mirror -R . |
Recursive FTP in Windows
Both wget and lftp are available in Windows as part of the Cygwin environment.