2014-08-29 105 views
2

我目前收到以下錯誤:由於參數(501)語法錯誤:文件傳輸協議和AS400

遠程服務器返回錯誤。

我有身體檢查服務器和文件確實存在,如果我打開一個命令提示符,然後輸入以下代碼它的工作原理:

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:

To obtain an instance of FtpWebRequest, use the Create method. You can also use the WebClient class to upload and download information from an FTP server. Using either of these approaches, when you specify a network resource that uses the FTP scheme (for example, " ftp://contoso.com ") the FtpWebRequest class provides the ability to programmatically interact with FTP servers.

The URI may be relative or absolute. If the URI is of the form " ftp://contoso.com/%2fpath " (%2f is an escaped '/'), then the URI is absolute, and the current directory is /path. If, however, the URI is of the form " ftp://contoso.com/path ", first the .NET Framework logs into the FTP server (using the user name and password set by the Credentials property), then the current directory is set to /path.

哪一個是AS400是如何期待數據將通過。

+0

您是否在瀏覽器中試過這個網址?在ftp客戶端中輸入登錄名,cd和get命令與通過代碼生成的任何url不一樣。 – 2014-08-29 14:32:42

回答

3

在某些情況下,/字符無效或被接受。

AS400可能需要通過使用/%2F更改,這將正確切換AS400上的目錄。例如:

ftp://192.168.1.2/%2FImages/%2FS12345.jpeg 

通過使用/%2F它允許它在目錄之間移動。

可以找到更多的細節here