先写一个信息类
class ServiceFileInfo
{
public static readonly string FilePath = @"ftp://10.66.xx.xx/log/";
public static readonly string UserID = "xxx";
public static readonly string UserPassword = "999";
}
再用WebClient, address参数要写明文件名,只有路径会报错
using (WebClient client = new WebClient())
{
client.Credentials = new NetworkCredential(ServiceFileInfo.UserID, ServiceFileInfo.UserPassword);
client.UploadFile(ServiceFileInfo.FilePath + "1.wav", WebRequestMethods.Ftp.UploadFile, @"D:\draft\zzz.wav");
}
如图,成功上传