strm = reqFTP.GetRequestStream();
strm.Write(buff, 0, buff.Length);
strm.Dispose();
strm.Close();
到了strm.Dispose();时就报错:
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
上传ftp出错,刚刚提问写错了,请帮忙
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- WorldMobile 2015-06-09 13:38关注
You can use this code to try:
protected void btnUploadFile_Click(object sender, System.EventArgs e)
{
FtpWebRequest myFtpWebRequest;
FtpWebResponse myFtpWebResponse;
StreamWriter myStreamWriter;myFtpWebRequest = (FtpWebRequest)WebRequest.Create("ftp://ftp_server_name/filename.ext"); myFtpWebRequest.Credentials = new NetworkCredential("username", "password"); myFtpWebRequest.Method = WebRequestMethods.Ftp.UploadFile; myFtpWebRequest.UseBinary = true; myStreamWriter = new StreamWriter(myFtpWebRequest.GetRequestStream()); myStreamWriter.Write(new StreamReader(Server.MapPath("filename.ext")).ReadToEnd()); myStreamWriter.Close(); myFtpWebResponse = (FtpWebResponse)myFtpWebRequest.GetResponse(); Response.Write("Upload File Complete, status: " + myFtpWebResponse.StatusDescription); myFtpWebResponse.Close(); }
If it is still not work, here is some posts that solved the similar errors. Hope it helps.
http://www.dreamincode.net/forums/topic/76361-file-upload-to-server/
http://forums.asp.net/t/1374306.aspx/1
Thanks
解决 无用评论 打赏 举报