软件编程
位置:首页>> 软件编程>> C#编程>> c# FTP上传文件实例代码(简易版)

c# FTP上传文件实例代码(简易版)

作者:jingxian  发布时间:2023-09-08 11:43:56 

标签:c#,FTP,上传文件

实例如下:


/// <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;
 }

来源:http://www.cnblogs.com/hanzhecheng/archive/2017/12/05/7988570.html

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com