使用curl下载上传ftp (一)

来源:互联网 发布:腾讯股票数据接口 编辑:程序博客网 时间:2024/05/18 11:50

使用curl下载上传ftp(一)

curl可以在shell下轻松上传下载ftp上的文件,相比ftp命令更具有优势,因为它能在单命令条件下,下载或者上传一个ftp文件,甚至可以删除文件。

下面看实例:

1. 列出ftp服务器上的目录列表:

curl ftp://malu.me/ –user name:passwd
curl ftp://malu.me/ –u name:passwd #简洁写法
curl ftp://name:passwd@malu.me #简洁写法2

2. 只列出目录,不显示进度条

curl ftp://malu.me –u name:passwd -s

3. 下载一个文件:

curl ftp://malu.me/size.zip –u name:passwd -o size.zip

root@OpenWrt:/# curl -u ftp:ftp -o 1.txt ftp://113.98.110.101/  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed100   189    0   189    0     0    243      0 --:--:-- --:--:-- --:--:--   244root@OpenWrt:/# 

4. 上载一个文件:

curl –u name:passwd -T size.mp3 ftp://malu.me/mp3/

root@OpenWrt:/# curl -u ftp:ftp -o 1.txt ftp://113.98.110.101/  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed100   189    0   189    0     0    243      0 --:--:-- --:--:-- --:--:--   244root@OpenWrt:/# 

5. 从服务器上删除文件(使用curl传递ftp协议的DELE命令):

curl –u name:passwd ftp://malu.me/ -X ‘DELE mp3/size.mp3’

6. 多文件下载
另外curl不支持递归下载,不过可以用数组方式下载文件,比如我们要下载1-10.gif连续命名的文件:

curl –u name:passwd ftp://malu.me/img/[1-10].gif –O #O字母大写

要连续下载多个文件:

curl –u name:passwd ftp://malu.me/img/[one,two,three].jpg –O #O字母大写