1、FluentFTP安装引用
FluentFTP库使用Nuget安装引用
1) 使用Nuget命令安装
PM> Install-Package FluentFTP -Version 27.0.1
2) 使用Nuget管理工具搜索"FluentFTP"
=>找到选择“安装”
相关文档:VS(Visual Studio)中Nuget的使用
2、FluentFTP使用示例代码
// 创建 FTP clientFtpClient client = new FtpClient("123.123.123.123");// 如果您不指定登录凭证,我们将使用"anonymous"用户帐户client.Credentials = new NetworkCredential("david", "pass123");//开始连接Serverclient.Connect();//获取“/htdocs”文件夹中的文件和目录列表foreach (FtpListItem item in client.GetListing("/htdocs")) {//如果是 fileif (item.Type == FtpFileSystemObjectType.File){// get the file sizelong size = client.GetFileSize(item.FullName);}// 获取文件或文件夹的修改日期/时间DateTime time = client.GetModifiedTime(item.FullName);// 计算服务器端文件的哈希值(默认算法)FtpHash hash = client.GetHash(item.FullName);}//上传 fileclient.UploadFile(@"C:\MyVideo.mp4", "/htdocs/MyVideo.mp4");// 上传的文件重命名client.Rename("/htdocs/MyVideo.mp4", "/htdocs/MyVideo_2.mp4");// 下载文件client.DownloadFile(@"C:\MyVideo_2.mp4", "/htdocs/MyVideo_2.mp4");// 删除文件client.DeleteFile("/htdocs/MyVideo_2.mp4");// 递归删除文件夹client.DeleteDirectory("/htdocs/extras/");// 判断文件是否存在if (client.FileExists("/htdocs/big2.txt")){ }// 判断文件夹是否存在if (client.DirectoryExists("/htdocs/extras/")){ }//上传一个文件,重试3次才放弃client.RetryAttempts = 3;client.UploadFile(@"C:\MyVideo.mp4", "/htdocs/big.txt", FtpExists.Overwrite, false, FtpVerify.Retry);// 断开连接! good bye!client.Disconnect();