如何在 Linux 上通过 FTP 递归下载文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/113886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to recursively download a folder via FTP on Linux
提问by Charles Ma
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.
我正在尝试使用命令行 ftp 客户端对文件夹进行 ftp,但到目前为止我只能使用“get”来获取单个文件。
采纳答案by Thibaut Barrère
You could rely on wget which usually handles ftp get properly (at least in my own experience). For example:
您可以依靠 wget 通常正确处理 ftp get(至少以我自己的经验)。例如:
wget -r ftp://user:[email protected]/
You can also use -m
which is suitable for mirroring. It is currently equivalent to -r -N -l inf
.
您还可以使用-m
适合镜像的哪个。它目前相当于-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:
如果凭据详细信息中有一些特殊字符,则可以指定--user
和--password
参数以使其工作。使用特定字符自定义登录的示例:
wget -r --user="user@login" --password="Pa$$wo|^D" ftp://server.com/
EDITAs pointed out by @asmaier, watch out that even if -r
is for recursion, it has a default max level of 5:
编辑正如@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.
-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
:
-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.
-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.
回答by Greg Hewgill
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.
如果您可以使用scp
代替ftp
,该-r
选项将为您执行此操作。我会检查您是否可以使用比 FTP 更现代的文件传输机制。
回答by Vinko Vrsalovic
ncftp -u <user> -p <pass> <server>
ncftp> mget directory
回答by Hank Gay
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.
如果可以,我强烈建议您tar
和bzip
(或gzip
任何漂浮在您的船上的东西)远程机器上的目录 - 对于任何大小的目录,带宽节省可能值得花时间压缩/解压缩。
回答by Jason Stevenson
Use WGet instead. It supports HTTP and FTP protocols.
请改用 WGet。它支持 HTTP 和 FTP 协议。
wget -r ftp://mydomain.com/mystuff
Good Luck!
祝你好运!
reference: http://linux.about.com/od/commands/l/blcmdl1_wget.htm
回答by Cypher
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.
有“ncftp”可用于在 linux 中安装。这适用于 FTP 协议,可用于递归下载文件和文件夹。在 linux 上工作。已用于递归文件夹/文件传输并且工作正常。
Check this link... http://www.ncftp.com/
检查此链接... http://www.ncftp.com/
回答by Jazz
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.
如果你想坚持使用命令行 FTP,你应该尝试 NcFTP。然后您可以使用 get -R 递归获取文件夹。您还将获得完成。
回答by Phillip
wget -r ftp://url
wget -r ftp://url
Work perfectly for Redhat and Ubuntu
完美适用于 Redhat 和 Ubuntu
回答by Rohit
toggle the prompt by PROMPT command.
通过 PROMPT 命令切换提示。
Usage:
用法:
ftp>cd /to/directory
ftp>prompt
ftp>mget *
回答by Ludovic Kuty
Just to complement the answer given by Thibaut Barrère.
只是为了补充 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.
- -nH 避免创建以服务器名称命名的目录
- -nc 避免在目标上已经存在的情况下创建新文件(它只是被跳过)
- --cut-dirs=5 允许我获取 /absolute/path/to/directory 的内容并将其放在我启动 wget 的目录中。数字 5 用于过滤掉路径的 5 个组件。双斜线表示一个额外的组件。