2 a529821345 a529821345 于 2015.06.09 21:21 提问

上传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).

3个回答

lzp_lrp
lzp_lrp   Ds   Rxr 2015.06.09 21: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://nickstips.wordpress.com/2010/10/25/c-ftp-upload-error-the-remote-server-returned-an-error-550-file-unavailable-e-g-file-not-found-no-access/

http://www.dreamincode.net/forums/topic/76361-file-upload-to-server/

http://forums.asp.net/t/1374306.aspx/1

Thanks

frank_20080215
frank_20080215   2015.06.10 07:33

FTP服务器没有指定,连接没有打开

a529821345
a529821345 我有2个环境,测试环境ok的,正式环境就不行了,代码完全一样
2 年多之前 回复
beacon_2011
beacon_2011   Rxr 2015.06.10 15:26

没有建立FTP连接,首先要建立连接

Csdn user default icon
上传中...
上传图片
插入图片