小编Ste*_*oly的帖子

FtpWebRequest类文件上传时出现550文件不可用错误.在FileZilla中正常工作

我搜索并发现了其他问题,但没有一个解决了我的问题.我正在尝试使用示例MSDN代码通过FTP上传文件.我得到远程服务器返回错误:(550)文件不可用(例如,找不到文件,没有访问)错误在这一行:ftpstream.Close();

    string inputfilepath = @"C:\DWF\test.txt";
    string ftpfilepath = "/abc/def/hij/klm/nop/test.txt";
    string ftphost = "my-ser-ver1:2121";
    //here correct hostname or IP of the ftp server to be given  

    string ftpfullpath = "ftp://" + ftphost + ftpfilepath;
    FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
    ftp.Credentials = new NetworkCredential("user", "pass");
    //userid and password for the ftp server to given  

    ftp.KeepAlive = true;
    ftp.UseBinary = true;

    ftp.Method = WebRequestMethods.Ftp.UploadFile;
    FileStream fs = File.OpenRead(inputfilepath);
    byte[] buffer = new byte[fs.Length];
    fs.Read(buffer, 0, buffer.Length);
    fs.Close();
    Stream ftpstream = ftp.GetRequestStream();
    ftpstream.Write(buffer, 0, buffer.Length); …
Run Code Online (Sandbox Code Playgroud)

.net c# ftp

5
推荐指数
1
解决办法
3万
查看次数

标签 统计

.net ×1

c# ×1

ftp ×1