我需要用F#编写一个程序,将文件推送到FTP服务器。是否有可以使用的库?我在网上找不到任何信息。有人能指点我一下吗?如果可能的话,提供一些示例代码会非常有帮助。
System.Net.WebRequest.Create
在给定ftp://
URL时表现良好。
要访问FTP特定的功能(例如上传文件),请将您的 WebRequest
对象强制转换为 FtpWebRequest
。
内置的FtpWebRequest
已经过时。FluentFTP是一个很棒的库,它经常得到更新。
#r "nuget: FluentFTP"
open FluentFTP
let ip = "45.33.2.79"
let username = "username"
let passwd = "s$cret"
let lpath = fsi.CommandLineArgs[1]
let rpath = fsi.CommandLineArgs[2]
let launch () =
use con = new FtpClient(ip, username, passwd)
con.Connect()
let status =
con.UploadFile(lpath, rpath, FtpRemoteExists.Overwrite, true, FtpVerify.Retry)
match status with
| FtpStatus.Success -> printfn "file uploaded OK"
| FtpStatus.Failed -> printfn "failed to upload file"
| _ -> printfn "skipped or unknown"
launch ()
let reqFTP: FtpWebRequest = WebRequest.Create(uri) :?> FtpWebRequest
。 - Tim Robinson