How to recursively download a folder via FTP on Linux

我试图使用命令行ftp客户端来ftp文件夹,但到目前为止,我只能使用'get'来获取单个文件。


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.

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.

  • ncftp -u <user> -p <pass> <server>
    ncftp> mget directory
    
    链接地址: http://www.djcxy.com/p/78114.html

    上一篇: Linux如何复制但不能覆盖?

    下一篇: 如何在Linux上通过FTP递归下载文件夹