使用cURL下载目录中的所有文件
我使用cURL尝试下载某个目录中的所有文件。
I am using cURL to try to download all files in a certain directory.
这里是我的文件列表:
>
我试图在bash脚本中执行: iiumlabs。[]。csv.pgp
和 iiumlabs *
guess curl在通配符上不大。
I have tried to do in bash script: iiumlabs.[].csv.pgp
and iiumlabs*
and I guess curl is not big on wildcards.
curl -u login:pass ftp.myftpsite.com/iiumlabs* -O
问题:如何使用cURL下载此文件目录?
question: how do i download this directory of files using cURL?
确定,考虑到您使用的是Windows,最简单的方法是使用标准 ftp
工具捆绑在一起。我在Windows XP上基于以下解决方案,希望它在其他版本上也能工作(或稍作修改)。
OK, considering that you are using Windows, the most simple way to do that is to use the standard ftp
tool bundled with it. I base the following solution on Windows XP, hoping it'll work as well (or with minor modifications) on other versions.
首先,您需要创建一个用于 ftp
程序的批处理(脚本)文件,包含它的说明。根据需要命名并加入:
First of all, you need to create a batch (script) file for the ftp
program, containing instructions for it. Name it as you want, and put into it:
curl -u login:pass ftp.myftpsite.com/iiumlabs* -O
open ftp.myftpsite.com
login
pass
mget *
quit
第一行在 ftp.myftpsite.com
处打开与ftp服务器的连接。以下两行指定了登录名和ftp要求的密码(用 login
和 pass
登录和密码,没有任何关键字)。然后,使用 mget *
获取所有文件。而不是 *
,您可以使用任何通配符。最后,使用 quit
关闭 ftp
程序,但不提供交互式提示。
The first line opens a connection to the ftp server at ftp.myftpsite.com
. The two following lines specify the login, and the password which ftp will ask for (replace login
and pass
with just the login and password, without any keywords). Then, you use mget *
to get all files. Instead of the *
, you can use any wildcard. Finally, you use quit
to close the ftp
program without interactive prompt.
如果您需要首先输入某个目录,请在 mget
之前添加 cd
命令。
If you needed to enter some directory first, add a cd
command before mget
. It should be pretty straightforward.
最后,编写该文件并运行 ftp
,如下所示:
Finally, write that file and run ftp
like this:
ftp -i -s:yourscript
其中 -i
禁用交互性(在下载文件之前询问), -s
where -i
disables interactivity (asking before downloading files), and -s
specifies path to the script you created.
很遗憾,Windows中的文件传输本身并不支持。但对于这种情况,您可能需要使用 PuTTy 工具。对于这种情况特别感兴趣的是 pscp
,这实际上是openssh scp
命令的PuTTy计数器部分
Sadly, file transfer over SSH is not natively supported in Windows. But for that case, you'd probably want to use PuTTy tools anyway. The one of particular interest for this case would be pscp
which is practically the PuTTy counter-part of the openssh scp
command.
语法类似于 copy
命令,并且它支持通配符:
The syntax is similar to copy
command, and it supports wildcards:
pscp -batch login@mysshsite.com:iiumlabs* .
如果使用密钥文件进行身份验证,则应使用 -i路径到密钥文件
。如果使用密码, -pw pass
。它还可以使用load -load your-session-name
参数重用使用PuTTy保存的会话。
If you authenticate using a key file, you should pass it using -i path-to-key-file
. If you use password, -pw pass
. It can also reuse sessions saved using PuTTy, using the load -load your-session-name
argument.