550 文件不可用错误与 FtpWebRequest 类文件上传.在

550 file unavailable error with FtpWebRequest class file upload. Works fine in FileZilla(550 文件不可用错误与 FtpWebRequest 类文件上传.在 FileZilla 中运行良好)
本文介绍了550 文件不可用错误与 FtpWebRequest 类文件上传.在 FileZilla 中运行良好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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	est.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(); 

我已经仔细检查了 URI 是否有空格,但没有.我可以使用具有相同用户登录名的 filezilla 完成此任务.没有奇怪的默认目录已经是我的 URI 的一部分.可以肯定的一件事是我正在连接到一个 unix 服务器,所以也许我缺少一个设置?

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?

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

推荐答案

这成功了.显然 CWD 命令行为在从 .NET 3.5 迁移到 4.0 时发生了变化.

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

这篇关于550 文件不可用错误与 FtpWebRequest 类文件上传.在 FileZilla 中运行良好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)