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

时间:2020-03-06 14:31:49  来源:igfitidea点击:

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

解决方案

如果我们可以使用scp代替ftp,那么-r选项将为我们完成此操作。我将检查是否可以使用比FTP更现代的文件传输机制。

我们可以依靠通常可以正确处理ftp的wget(至少以我自己的经验)。例如:

wget -r ftp://user:[email protected]/

我们也可以使用适用于镜像的-m。当前等效于-r -N -l inf。

如果我们在凭证详细信息中包含一些特殊字符,则可以指定--user--password参数使其生效。具有特定字符的自定义登录的示例:

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

编辑
正如@asmaier指出的那样,请注意,即使-r用于递归,它的默认最大级别也为5:

-r
       --recursive
           Turn on recursive retrieving.

       -l depth
       --level=depth
           Specify recursion maximum depth level depth.  The default maximum depth is 5.

如果我们不想错过子目录,最好使用镜像选项-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.

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

如果可以的话,我强烈建议我们将tar和bzip(或者gzip,随便什么都浮上)在远程计算机上的目录中,以用于任何大小的目录,节省带宽可能值得花时间压缩/解压缩。

改用WGet。它支持HTTP和FTP协议。

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

祝你好运!

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

有" ncftp"可用于在Linux中安装。这适用于FTP协议,可用于递归下载文件和文件夹。在linux上工作。已被使用,并且在递归文件夹/文件传输中正常工作。

检查此链接... http://www.ncftp.com/

如果要坚持使用命令行FTP,则应尝试使用NcFTP。然后,我们可以使用get -R递归获取文件夹。我们还将获得完成。

wget -r ftp:// URL

非常适合Redhat和Ubuntu