550文件不可用误差的FtpWebRequest类文件上传。在FileZilla中工作正常误差、不可用、文件上传、正常

2023-09-03 05:15:55 作者:孑然一身

我搜查,发现在这个其他问题但没有解决我的问题。我试图通过上传使用示例FTP MSDN code文件。我得到的远程服务器返回错误:(550)文件不可用(例如,文件没找到,没有权限)错误在这条线:ftpstream.Close();

 字符串inputfilepath = @C:\ DWF \ test.txt的;
    字符串ftpfilepath =/abc/def/hij/klm/nop/test.txt;
    字符串ftphost =我-SER-ver1时:2121;
    //这里正确的FTP服务器的主机名或IP给予

    字符串ftpfullpath =FTP://+ ftphost + ftpfilepath;
    的FtpWebRequest FTP =(的FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
    ftp.Credentials =新的NetworkCredential(用户,通行证);
    //用户名和密码,FTP服务器给定

    ftp.KeepAlive = TRUE;
    ftp.UseBinary = TRUE;

    ftp.Method = WebRequestMethods.Ftp.UploadFile;
    的FileStream FS = File.OpenRead(inputfilepath);
    byte []的缓冲区=新的字节[fs.Length]
    fs.Read(缓冲液,0,buffer.Length);
    fs.Close();
    流ftpstream = ftp.GetRequestStream();
    ftpstream.Write(缓冲液,0,buffer.Length);
    ftpstream.Close();
 

我有双重检查的URI的空格,有没有。我能够完成使用FileZilla的使用相同的用户登录此任务。没有古怪的默认目录已经是我的URI的一部分。有一点可以肯定的是,我连接到​​UNIX服务器,所以也许有一个设置我失踪?

编辑#1(从System.Net添加错误日志)

  System.Net信息:0: - 【220 Oracle内容服务FTP服务器准备就绪] [7584] FtpControlStream#62182359收到的响应

System.Net信息:0:[7584] FtpControlStream#62182359  - 发送命令[USER myuser的]

System.Net信息:0: - 【331需要myuser的密码] [7584] FtpControlStream#62182359收到的响应

System.Net信息:0:[7584] FtpControlStream#62182359  - 发送命令[PASS ********]

System.Net信息:0:[7584] FtpControlStream#62182359  - 收到的响应[230登录成功。]

System.Net信息:0:[7584] FtpControlStream#62182359  - 发送命令[OPTS UTF8上]

System.Net信息:0:[7584] FtpControlStream#62182359  - 收到的响应[500命令不支持:OPTS]

System.Net信息:0:[7584] FtpControlStream#62182359  - 发送命令[PWD]

System.Net信息:0:[7584] FtpControlStream#62182359  - 收到的响应[257」/「]

System.Net信息:0:[7584] FtpControlStream#62182359  - 发送命令[TYPE I]

System.Net信息:0:[7584] FtpControlStream#62182359  - 收到的响应[200类型设置为一]

System.Net信息:0:[7584] FtpControlStream#62182359  - 发送命令[PASV]

System.Net信息:0:[7584] FtpControlStream#62182359  - 收到的响应[227进入被动模式(10,8,9,50,77,53)

System.Net信息:0:[7584] FtpControlStream#62182359  - 发送命令[STOR ABC / DEF / HIJ /荷航/ NOP / test.txt的]

System.Net信息:0: - 【150确定要发送数据] [7584] FtpControlStream#62182359收到的响应

System.Net详细:0:[7584]退出的FtpWebRequest#10964107 :: GetRequestStream()

System.Net信息:0:[7584] FtpControlStream#62182359  - 收到的响应[550拒绝访问]

System.Net信息:0:[7584]的FtpWebRequest#10964107::(释放FTP连接#62182359)
 

解决方案 C 判断远程ftp文件是否存在

这并获得成功。显然是在移动的CWD命令的行为改变,从.NET 3.5至4.0。

您必须先调用这个链接的方式。

http://support.microsoft.com/kb/2134299

I'm searched and found other questions on this but none have solved my issues. I'm trying to upload a file via FTP using sample MSDN code. I get the The remote server returned an error: (550) File unavailable (e.g., file not found, no access) error on this line: 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);
    ftpstream.Close(); 

I have double checked the URI for blank spaces and there are none. I am able to complete this task using filezilla with the same user login. There is no oddball default directory that is already part of my URI. One thing for sure is that I am connecting to a unix server so maybe there is a setting I am missing?

Edit #1 (Added error log from System.Net)

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Received response [220 Oracle Content Services FTP Server ready.]

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Sending command [USER myuser]

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Received response [331 Password required for myuser.]

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Sending command [PASS ********]

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Received response [230 Login successful.]

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Sending command [OPTS utf8 on]

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Received response [500 Command not supported: OPTS]

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Sending command [PWD]

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Received response [257 "/"]

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Sending command [TYPE I]

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Received response [200 TYPE set to I.]

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Sending command [PASV]

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Received response [227 Entering Passive Mode (10,8,9,50,77,53)]

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Sending command [STOR abc/def/hij/klm/nop/test.txt]

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Received response [150 Ok to send data.]

System.Net Verbose: 0 : [7584] Exiting FtpWebRequest#10964107::GetRequestStream() 

System.Net Information: 0 : [7584] FtpControlStream#62182359 - Received response [550 Access denied.]

System.Net Information: 0 : [7584] FtpWebRequest#10964107::(Releasing FTP connection#62182359.)

解决方案

This did the trick. apparently the CWD command behavior changed in the move from .NET 3.5 to 4.0.

You have to first call the method in this link.

http://support.microsoft.com/kb/2134299