您的位置 首页 php

「按键精灵」服务器文件的ftp上传、下载、删除文件

大家好,我是公众号3分钟学堂的郭立员,今天直接分享一个 ftp 上传、下载、删除文件的源码,主要用的是curl命令。

按键代码

  Import  "shanhai.lua"


'-------------------定义参数--------------------
Dim name="ftp2935874"                            'ftp账号
Dim password="**********"                        'ftp密码
Dim ftpPath="ftp://host166.gotoftp4.cn/"         'ftp地址
Dim filepath="/sdcard/pictures/0.txt"            '本地文件路径
Dim downloadpath=ftpPath&"wwwroot/0.txt"         '文件服务器地址
Dim pathname="wwwroot/0.txt"                     '文件名称(包括文件夹路径)
'----------------------------------------------


//上传文件
shanhai.execute ("curl -u " & name & ":" & password & " -T " & filepath & " " & ftpPath & "wwwroot/")


//下载文件
shanhai.execute ("curl " & downloadpath & " -u " & name & ":" & password & " -o " & filepath)


//删除文件
shanhai.execute ("curl -u " & name & ":" & password & " " & ftpPath & " -X 'DELE " & pathname & "'")

  

CURL参考资料

-o out ?将指定curl返回保存为out文件,内容从html/jpg到各种MIME类型文件

-O ?按服务器上的名称保存下载的文件

-r/–range ?from-to 下载指定range内的数据

-C 在保存文件时进行续传

-A/–user-agent ?<ua> ?指定发送请求的用户代理 如 curl -A My-Agent/1.0.0 www.apple.com?

-x ?ip:port 指定使用的http代理,如curl -x 192.168.1.1:8080 www.apple.com

-D head.txt ?将服务器的返回的header保存为文件,头部的 cookie 也可被保存 ? curl -D header.txt www.apple.com

-c <file> 保存服务器的cookie文件

-b/–cookie ?<name=data> ? 向服务器提交cookie,若无=则name视为文件名 ?curl -b cookie.txt www.apple.com

-e url ?设置引用头的值

-T localfile ?向服务器PUT文件 如curl -T 1.mp3 ?www.apple.com/upload.php

-d <key=value> ?向服务器POST表单数据 如curl -d “order=111&count=2”

-F <key=value> 向服务器POST表单?curl -F “web=@index.html;type=text/html” url.com

如果希望从本地文件中获取表单数据,则在文件名前加@ 如 curl -d @data.xml

若希望从标准输入获取则用curl -d –

-E cert.pem ?指定本地证书

-H <header:value> ?为HTTP请求设置任意header及值。如curl -H “Connection:keep-alive”

-I ?构造一个HEAD请求

-X/–request method 用户定义的HTTP请求方法名如 curl -X GET www.baidu.com

–compressed 采用压缩方式接收返回数据

–connect-timeout <s> 设置超时时间

-v 详细输出,包含请求和响应的首部

文章来源:智云一二三科技

文章标题:「按键精灵」服务器文件的ftp上传、下载、删除文件

文章地址:https://www.zhihuclub.com/153284.shtml

关于作者: 智云科技

热门文章

网站地图