.net FTP上传文件

时间:2022-10-14 17:43:20

 

FTP上传文件代码实现:

private void UploadFileByWebClient()

{
WebClient webClient = new WebClient();
webClient.Credentials = new NetworkCredential("erp", "123456789");
string ftpUrl = "ftp://10.20.30.40/Doc/";
string fileName = @"F:\电脑安装工具\test\file3G.rar";
string uploadFilePath = string.Format("{0}{1}{2}",
ftpUrl,
DateTime.Now.ToString("yyyyMMddHHmmss"),
Path.GetFileName(fileName));
byte[] fileLength = webClient.UploadFile(uploadFilePath, fileName);
}