问题描述
- 上传ftp出错,刚刚提问写错了,请帮忙
-
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).
解决方案
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
解决方案二:
FTP服务器没有指定,连接没有打开
解决方案三:
没有建立FTP连接,首先要建立连接
时间: 2024-08-01 16:12:31