使用 cURL 下载目录中的所有文件 [英] Downloading all the files in a directory with cURL

查看:197
本文介绍了使用 cURL 下载目录中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 cURL 尝试下载某个目录中的所有文件.

I am using cURL to try to download all files in a certain directory.

这是我的文件列表的样子:

here's what my list of files looks like:

我尝试在 bash 脚本中执行:iiumlabs.[].csv.pgpiiumlabs*,我猜 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 要求的密码(用登录名和密码替换 loginpass,不带任何关键字).然后,您使用 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 本身并不支持通过 SSH 传输文件.但对于这种情况,您可能想要使用 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 path-to-key-file 传递它.如果使用密码,-pw pass.它还可以重用使用 PuTTy 保存的会话,使用 load -load your-session-name 参数.

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.

这篇关于使用 cURL 下载目录中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆