我目前收到以下错误:
远程服务器返回错误:(501)参数或参数中的语法错误 .
我已经检查了服务器并且文件确实存在,如果我打开命令提示符并键入以下代码它可以工作:
ftp
open 192.168.1.2
cd /Images
get S12345.jpeg
这是正常的,但是一旦我尝试通过此代码连接:
private bool DownloadPod(string server)
{
string[] allocate = server.Split('\\');
string ftp = @"ftp://192.168.1.2/Images/" + allocate.Last();
Uri uri = new Uri(ftp);
// The code path for uri: ftp://192.168.1.2/Images/S12345.jpeg
var request = WebRequest.Create(uri) as FtpWebRequest;
if(request != null)
{
request.Method = WebRequestMethods.Ftp.DownloadFile;
// Left credentials off for security.
request.Credentials = new NetworkCredential(@"", @"");
// The line that triggers the error (response)
using(FtpWebResponse response = request.GetResponse() as FtpWebResponse)
using(Stream stream = response.GetResponseStream())
using(StreamReader reader = new StreamReader(stream))
{
reader.ReadToEnd();
return true;
}
}
return false;
}
有人可以向我解释为什么这不起作用?
-
凭据在命令提示符下工作
-
在服务器上物理文件
-
可以从命令提示符下载
根据MSDN:
要获取FtpWebRequest的实例,请使用Create方法 . 您还可以使用WebClient类从FTP服务器上载和下载信息 . 使用这些方法中的任何一种,当您指定使用FTP方案的网络资源(例如,“ftp://contoso.com”)时,FtpWebRequest类提供以编程方式与FTP服务器交互的功能 . URI可以是相对的或绝对的 . 如果URI的格式为“ftp://contoso.com/%2fpath”(%2f是转义'/'),那么URI是绝对的,当前目录是/ path . 但是,如果URI的格式为“ftp://contoso.com/path”,则首先.NET Framework登录到FTP服务器(使用Credentials属性设置的用户名和密码),然后是当前目录设置为/ path .
这就是AS400期望数据通过的方式 .
1 回答
在某些情况下,
/
字符无效或不被接受 .AS400可能需要使用
/%2F
进行更改,这将正确切换AS400上的目录 . 例如:通过使用
/%2F
,它允许它在目录之间移动 .其他详细信息可以在here找到 .