Tutorial :How to recursively download a folder via FTP on Linux [closed]



Question:

I'm trying to ftp a folder using the command line ftp client, but so far I've only been able to use 'get' to get individual files.


Solution:1

You could rely on wget which usually handles ftp get properly (at least in my own experience). For example:

wget -r ftp://user:pass@server.com/  

You can also use -m which is suitable for mirroring. It is currently equivalent to -r -N -l inf.

If you've some special characters in the credential details, you can specify the --user and --password arguments to get it to work. Example with custom login with specific characters:

wget -r --user="user@login" --password="Pa$$wo|^D" ftp://server.com/  

EDIT As pointed out by @asmaier, watch out that even if -r is for recursion, it has a default max level of 5:

       -r         --recursive             Turn on recursive retrieving.           -l depth         --level=depth             Specify recursion maximum depth level depth.  The default maximum depth is 5.  

If you don't want to miss out subdirs, better use the mirroring option, -m:

       -m         --mirror             Turn on options suitable for mirroring.  This option turns on recursion and time-stamping, sets infinite             recursion depth and keeps FTP directory listings.  It is currently equivalent to -r -N -l inf             --no-remove-listing.  


Solution:2

Just to complement the answer given by Thibaut Barrère.

I used

wget -r -nH --cut-dirs=5 -nc ftp://user:pass@server//absolute/path/to/directory  

Note the double slash after the server name. If I don't put an extra slash the path is relative to the home directory of user.

  • -nH avoids the creation of a directory named after the server name
  • -nc avoids creating a new file if it already exists on the destination (it is just skipped)
  • --cut-dirs=5 allows me to take the content of /absolute/path/to/directory and to put it in the directory where I launch wget. The number 5 is used to filter out the 5 components of the path. The double slash means an extra component.


Solution:3

ncftp -u <user> -p <pass> <server>  ncftp> mget directory  


Solution:4

If lftp is installed on your machine, use mirror dir. And you are done. See the comment by Ciro below if you want to recursively download a directory.


Solution:5

If you can use scp instead of ftp, the -r option will do this for you. I would check to see whether you can use a more modern file transfer mechanism than FTP.


Solution:6

There is 'ncftp' which is available for installation in linux. This works on the FTP protocol and can be used to download files and folders recursively. works on linux. Has been used and is working fine for recursive folder/file transfer.

Check this link... http://www.ncftp.com/


Solution:7

Use WGet instead. It supports HTTP and FTP protocols.

wget -r ftp://mydomain.com/mystuff  

Good Luck!

reference: http://linux.about.com/od/commands/l/blcmdl1_wget.htm


Solution:8

If you want to stick to command line FTP, you should try NcFTP. Then you can use get -R to recursively get a folder. You will also get completion.


Solution:9

If you can, I strongly suggest you tar and bzip (or gzip, whatever floats your boat) the directory on the remote machineâ€"for a directory of any significant size, the bandwidth savings will probably be worth the time to zip/unzip.


Solution:10

wget -r ftp://url

Work perfectly for Redhat and Ubuntu


Solution:11

You should not use ftp. Like telnet it is not using secure protocols, and passwords are transmitted in clear text. This makes it very easy for third parties to capture your username and password.

To copy remote directories remotely, these options are better:

  • rsync is the best-suited tool if you can login via ssh, because it copies only the differences, and can easily restart in the middle in case the connection breaks.

  • ssh -r is the second-best option to recursively copy directory structures.

See:


Solution:12

Try mget:

   mget remote-files                Expand the remote-files on the remote machine and do a get for each file  name  thus  produced.                See  glob  for  details on the filename expansion.  Resulting file names will then be processed                according to case, ntrans, and nmap settings.  Files are transferred  into  the  local  working                directory, which can be changed with ‘lcd directory’; new local directories can be created with                ‘! mkdir directory’.  

You might also need to switch off the prompt so it does not ask for every file (see the propmt command)

But using scp or rsync over ssh is probably better than ftp if you can.

To recap:

cd /dir  prompt  interactive mode off  mget *  


Solution:13

toggle the prompt by PROMPT command.

Usage:

ftp>cd /to/directory      ftp>prompt      ftp>mget  *  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »