您的位置:首页 > 编程语言 > ASP

Asp.net 通过Ftp上传文件

2011-03-14 10:03 417 查看
public static void Upload(string filePath)
{
FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create("ftp://10.3.128.203/test.txt");
ftp.Credentials = new NetworkCredential("ftptest", "");
ftp.Method = WebRequestMethods.Ftp.UploadFile;
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
using (Stream stream = ftp.GetRequestStream())
{
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, bytes.Length);
stream.Write(bytes, 0, bytes.Length);
stream.Close();
}
fs.Close();
}
}

http://blog.blueshop.com.tw/hent/archive/2007/11/13/53332.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: