[按键精灵]看了这期文章就不用再去别处找ftp插件了,仅适用安卓按键

今天整理一下使用curl命令实现的ftp功能。

参照群里他们发的插件截图:

废话不多说,直接上代码:

Import "shanhai.lua"
Dim name="ftp"                                   'ftp账号
Dim password="123456"                            'ftp密码
Dim ftpPath="ftp://43.142.111.170/"              'ftp地址
Dim filepath="/sdcard/pictures/xx.txt"           '本地文件
Dim ftpfile="xx.txt"                             '服务器上文件名称
Dim folder="abc"                                 '文件夹名字
Dim OldPath="sss.txt"                            '原名字
Dim NewPath="ss.txt"                             '新名字
/*
//上传文件
upload(name,password,filepath,ftpPath)
Function upload(name,password,filepath,ftpPath)
  shanhai.execute ("curl -u " & name & ":" & password & " -T " & filepath & " " & ftpPath)
End Function

//下载文件
download(name,password,filepath,ftpPath,ftpfile)
Function download(name,password,filepath,ftpPath,ftpfile)
  shanhai.execute ("curl " & ftpPath&ftpfile & " -u " & name & ":" & password & " -o " & filepath)
End Function

//删除文件
delefile(name,password,ftpPath,ftpfile)
Function delefile(name,password,ftpPath,ftpfile)
  shanhai.execute ("curl -u " & name & ":" & password & " " & ftpPath & " -X 'DELE " & ftpfile & "'")
End Function

//删除文件夹
delefolder(name,password,ftpPath,folder)
Function delefolder(name,password,ftpPath,folder)
  shanhai.execute ("curl -u " & name & ":" & password & " " & ftpPath & " -X 'RMD " & folder & "'")
End Function

//查看文件夹
scan(name,password,ftpPath)
Function scan(name, password, ftpPath)
    dim f= shanhai.execute ("curl -u " & name & ":" & password & " " &ftpPath)
  TracePrint f
End Function

//创建文件夹
createfolder(name,password,filepath,ftpPath,folder)
Function createfolder(name,password,filepath,ftpPath,folder)
  shanhai.execute ("curl -u " & name & ":" & password & " " &ftpPath &" -X 'MKD "&folder&"'")
End Function

//重命名
renamefile(name,password,ftpPath,OldPath,NewPath)
Function renamefile(name,password,ftpPath,OldPath,NewPath)
  shanhai.execute ("curl -u " & name & ":" & password & " " & ftpPath & " -Q 'RNFR "&OldPath&"' -Q 'RNTO "&NewPath&"'")
End Function
*/

//重命名
renamefile(name,password,ftpPath,OldPath,NewPath)
Function renamefile(name,password,ftpPath,OldPath,NewPath)
  shanhai.execute ("curl -u " & name & ":" & password & " " & ftpPath & " -Q 'RNFR "&OldPath&"' -Q 'RNTO "&NewPath&"'")
End Function

转载自微信公众号:3分钟学堂