gpt4 book ai didi

c# - FtpWebRequest 类文件上传时出现 550 文件不可用错误。在 FileZilla 中运行良好

转载 作者:太空狗 更新时间:2023-10-29 22:27:47 26 4
gpt4 key购买 nike

我搜索并发现了其他关于此的问题,但没有一个能解决我的问题。我正在尝试使用示例 MSDN 代码通过 FTP 上传文件。我收到 The remote server returned an error: (550) File unavailable (e.g., file not found, no access) 此行错误: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();

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

编辑 #1(添加来自 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.)

最佳答案

这成功了。显然,CWD 命令行为在从 .NET 3.5 到 4.0 的过程中发生了变化。

您必须先调用此链接中的方法。

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

关于c# - FtpWebRequest 类文件上传时出现 550 文件不可用错误。在 FileZilla 中运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9621755/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com