curl –ftp-ssl抓取远程目录中的所有文件

是否有可能使用curl获取目录中的所有文件? 这是我的string到目前为止:

curl --ftp-ssl -k ftp://user:pass@IP 

这将列出用户FTP目录中的文件,如何调整此string以获取(RETR)远程目录中的所有文件?

AFAIK,没有这样的选项来下载一个目录curl ,所以你必须先获得列表,并curl按文件下载文件,如下所示:

 $ curl -s ftp://user:pass@IP/path/to/folder/ | \ grep -e '^-' | awk '{ print $9 }' | \ while read f; do \ curl -O ftp://user:pass@IP/path/to/folder/$f; \ done 

你也可以通过xargs来并行化这个过程:

 curl -s "ftp://user:pass@IP/path/to/folder/" \ | grep -e '^-' \ | awk '{ print $9 }' \ | xargs -I {} -P ${#procs} curl -O "ftp://user:pass@IP/path/to/folder/{}" 

这里有更多可重复使用的脚本来完成量子的curl | pipe | while解决scheme:

 #!/bin/bash # # Use cURL to download the files in a given FTPS directory (FTP over SSL) # eg: # curl_get_ftp_dir -u myUserName -p myPassword -d ftps://ftpserver.com/dir1/dir2 # Optionally, use: # -k - to ignore bad SSL certificates # --config userPassFile - to use the contents of a file including myUserName:myPassword in place of command line arguments # --silent - to silently download (otherwise cURL will display stats per file) while [[ $# -gt 1 ]] do key="$1" case $key in -u|--username) user="$2" shift ;; -p|--password) pass="$2" shift ;; -d|--dir|--directory) ftpDir="$2" shift ;; -k|--ignoreSSL|--ignoreBadSSLCertificate) ignoreBadSSLCertificate="-k" ;; -s|--silent) silent="-s" ;; -K|--config|--configFile) config="$2" shift ;; *) echo "Unknown Option!" ;; esac shift done if [ -z "${config+x}" ]; then CURL_OPTS="$silent --ftp-ssl $ignoreBadSSLCertificate -u $user:$pass" else #CURL_OPTS="$silent --ftp-ssl $ignoreBadSSLCertificate --config $config" #Originally intended to be a curl config file - for simplicity, now just a file with username:password in it #Be sure to chmod this file to either 700, 400, or 500 CURL_OPTS="$silent --ftp-ssl $ignoreBadSSLCertificate -u $(cat $config)" fi curl $CURL_OPTS $ftpDir | \ grep -e '^-' | awk '{ print $9 }' | \ while read f; do \ curl -O $CURL_OPTS $ftpDir/$f; \ done