1、FluentFTP类库简介
FluentFTP是一款老外开发的基于.Net的支持FTP及的FTPS 的FTP类库,FluentFTP是完全托管的FTP客户端,被设计为易于使用和易于扩展。它支持文件和目录列表,上传和下载文件和SSL / TLS连接。它可以连接到Unix和Windows IIS建立FTP服务器。
2、简单使用
安装FluentFTP类库程序包
Install-Package FluentFTP -Version 33.0.3
更多版本:
https://www.nuget.org/packages/FluentFTP
核心代码
使用的FtpClient构造函数:
using System;
using System.IO;
using FluentFTP;
namespace CallApp
{
class Program
{
static void Main(string[] args)
{
string host = "xxx";
string username = "xxx";
string password = "xxx";
string uploadFile = $@"E:\Works\Code\2020\Java\word\test.docx";
using FtpClient ftpClient = new FtpClient(host, username, password);
// 方法一:以文件流的方式上传文件
using FileStream fileStream = new FileStream(uploadFile, FileMode.Open);
// 参数一:文件流,参数二:ftp相对路径 + 文件名
ftpClient.Upload(fileStream, "creates/" + Path.GetFileName(uploadFile));
// 方法二:直接上传文件
// 参数一:本地文件路径,参数二:ftp相对路径 + 文件名
ftpClient.UploadFile(uploadFile, "creates/" + Path.GetFileName(uploadFile));
}
}
}
路漫漫其修远兮,吾将上下而求索
译文:在追寻真理方面,前方的道路还很漫长,但我将百折不挠,不遗余力地去追求和探索。
如果您有什么好的想法与方法,欢迎在评论区留言,我们一起讨论~