bash - 使用 cURL 下载目录中的所有文件

标签 bash shell curl ftp sftp

我正在使用 cURL 尝试下载特定目录中的所有文件。

这是我的文件列表:

enter image description here

我尝试在 bash 脚本中做:iiumlabs.[].csv.pgpiiumlabs* 我猜 curl 在通配符上并不大。

curl -u login:pass ftp.myftpsite.com/iiumlabs* -O

问题:如何使用 cURL 下载此目录的文件?

最佳答案

如果你不习惯 curl ,你可能想使用 wget在递归模式下但将其限制为一级递归,请尝试以下操作;

wget --no-verbose --no-parent --recursive --level=1 \
--no-directories --user=login --password=pass ftp://ftp.myftpsite.com/
  • --no-parent :递归检索时永远不要提升到父目录。
  • --level=depth : 指定递归最大深度级别深度。默认最大深度为五层。
  • --no-directories :递归检索时不创建目录层次结构。
  • --delete-after : 如果下载后需要删除文件可以加上。
  • --no-host-directories :直接在“.”中下载当前文件夹,而不是创建以域命名的目录。
  • --no-clobber : 跳过会下载到现有文件的下载
  • --continue : 继续获取部分下载的文件以提高稳定性
  • 结合cd :定义目标目录

所以这个示例看起来像下面这样:

cd /home/destination/folder \
&& wget --no-verbose --no-parent --recursive --level=1 \
--no-directories --no-host-directories \
--no-clobber --continue \ 
--user=login --password=pass ftp://ftp.myftpsite.com/

关于bash - 使用 cURL 下载目录中的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11783280/

相关文章:

linux - 进程的最大物理内存使用量

bash - 通过 bash 删除冗余

linux - 杀死 ssh session 会杀死正在运行的进程

linux - Samba、其他非交互式帐户 - noshell、nologin 或空白?

ruby - 如何使用 'wget'安装RVM?

ruby-on-rails - 如何搜索看起来像上传图片的图片

Bash 更新问题

bash - 字符串比较不起作用

c# - 使用 asp.net mvc 应用程序的 HttpClient post 请求 WebApi

bash - curl 在独立运行和 bash for 循环中的行为不同