实例如下:
/// <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;
}
以上这篇c# FTP上传文件实例代码(简易版)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持靠谱客。
最后
以上就是高挑画笔最近收集整理的关于c# FTP上传文件实例代码(简易版)的全部内容,更多相关c#内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复