c# FluentFTP FTP上传

修改编码方式为GBK

            ftpClient.Encoding = Encoding.GetEncoding("GB2312");
            //ftpClient.Config.DataConnectionType = FtpDataConnectionType.AutoActive;
            ftpClient.Config.Navigate = FtpNavigate.Auto;
// create an FTP client and specify the host, username and password
// (delete the credentials to use the "anonymous" account)
var client = new FtpClient("123.123.123.123", "david", "pass123");

// connect to the server and automatically detect working FTP settings
client.AutoConnect();

// get a list of files and directories in the "/htdocs" folder
foreach (FtpListItem item in client.GetListing("/htdocs")) {

	// if this is a file
	if (item.Type == FtpObjectType.File) {

		// get the file size
		long size = client.GetFileSize(item.FullName);

		// calculate a hash for the file on the server side (default algorithm)
		FtpHash hash = client.GetChecksum(item.FullName);
	}

	// get modified date/time of the file or folder
	DateTime time = client.GetModifiedTime(item.FullName);

}

// upload a file
client.UploadFile(@"C:\MyVideo.mp4", "/htdocs/MyVideo.mp4");

// move the uploaded file
client.MoveFile("/htdocs/MyVideo.mp4", "/htdocs/MyVideo_2.mp4");

// download the file again
client.DownloadFile(@"C:\MyVideo_2.mp4", "/htdocs/MyVideo_2.mp4");

// compare the downloaded file with the server
if (client.CompareFile(@"C:\MyVideo_2.mp4", "/htdocs/MyVideo_2.mp4") == FtpCompareResult.Equal) { }

// delete the file
client.DeleteFile("/htdocs/MyVideo_2.mp4");

// upload a folder and all its files
client.UploadDirectory(@"C:\website\videos\", @"/public_html/videos", FtpFolderSyncMode.Update);

// upload a folder and all its files, and delete extra files on the server
client.UploadDirectory(@"C:\website\assets\", @"/public_html/assets", FtpFolderSyncMode.Mirror);

// download a folder and all its files
client.DownloadDirectory(@"C:\website\logs\", @"/public_html/logs", FtpFolderSyncMode.Update);

// download a folder and all its files, and delete extra files on disk
client.DownloadDirectory(@"C:\website\dailybackup\", @"/public_html/", FtpFolderSyncMode.Mirror);

// delete a folder recursively
client.DeleteDirectory("/htdocs/extras/");

// check if a file exists
if (client.FileExists("/htdocs/big2.txt")) { }

// check if a folder exists
if (client.DirectoryExists("/htdocs/extras/")) { }

// upload a file and retry 3 times before giving up
client.Config.RetryAttempts = 3;
client.UploadFile(@"C:\MyVideo.mp4", "/htdocs/big.txt", FtpRemoteExists.Overwrite, false, FtpVerify.Retry);

// disconnect! good bye!
client.Disconnect();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值