c# FTP上传文件实例代码(简易版)
时间:2021-03-15 09:50:43|栏目:.NET代码|点击: 次
实例如下:
/// <summary> /// 上传ftp服务 /// </summary> /// <param name="path">文件地址</param> /// <returns></returns> public string Upload(string path) { var client = new WebClient(); client.Credentials = new NetworkCredential("fptuser", "ftppwd");//用户名和密码 client.BaseAddress = "ftpurl";//ftp地址 string ftpPath = client.BaseAddress + "/TestFileUpLoad/" + Guid.NewGuid();//上传fptp路径 string returnPath = ""; try { client.UploadFile(ftpPath, path); returnPath = ftpPath; } catch (Exception ex) { ///错误信息处理 } return returnPath; }
上一篇:值类型和引用类型的区别深入理解
栏 目:.NET代码
本文标题:c# FTP上传文件实例代码(简易版)
本文地址:http://www.codeinn.net/misctech/81082.html