2012-07-12 96 views
3

我正在ftp服務器上創建一個文件。但是在服務器上創建文件之前,我還檢查它是否已經存在。但是,大部分系統工作正常,但我的客戶之一有問題。當他運行應用程序時,它會拋出system.formatexception i-e輸入字符串的格式不正確。輸入字符串格式在ftp web請求中不正確

我無法理解這個問題。有誰能夠幫助我?

以下是創建文件的代碼。

public string createFile(string filename1) 
      { 

      StreamWriter sw1 = null; 
      System.Net.FtpWebRequest tmpReq1; 
      try 
      { 
      tmpReq1 = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create("ftp://ftp.dunyameri.com/pt/" + filename1); 
      tmpReq1.Credentials = new System.Net.NetworkCredential("[email protected]", "xxxxx"); 
      FtpWebResponse response = (FtpWebResponse)tmpReq1.GetResponse(); 
      } 
      catch (WebException ex) 
      { 
       FtpWebResponse response2 = (FtpWebResponse)ex.Response; 
       if (response2.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable) 
        { 
         // I am creating file here 
        } 
        else 
        { 
         return ex.ToString(); 
        } 
      } 
      return "File Created"; 

     } 

我在互聯網上搜索它可能是因爲字符串包含0或點。在這個特定的系統情況下,文件名包含點和0.是否因爲這種類型的文件名?

Exception description

感謝, 函數naveed

+4

它會拋出哪條線? – 2012-07-12 13:50:58

+0

儘管我正在捕捉web異常,但仍然得到了system.formatexception,但在嘗試部分通過此異常中的行。 – 2012-07-12 13:56:54

+0

@NaveedQamar filename1內的值是什麼 – HatSoft 2012-07-12 14:03:20

回答

0

我最好的猜測是,filename1開始於/字符。您可以使用Path.Combine方法來處理這種情況:

var path = Path.Combine("ftp://ftp.dunyameri.com/pt/", filename1); 
var tmpReq1 = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(path); 
... 
0

URL應該是這樣的 「的ftp://」 +使用者名稱+ 「:」 +密碼+ 「@」 + serverAddress + 「:」 + serverPort + 「/」+文件。

嘗試添加端口。

0

類的FtpWebRequest沒有創建方法星立http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest_methods

的例子在鏈接顯示蒙上WebRequest.Create到的FtpWebRequest這可能是問題

+0

cntsnwv0cn145.xx.xx.xxx.net-file.csv這是在這種特殊情況下的值...我試過使用IP 192.001.012.211-file.csv,但它不起作用。但是,當我在我的系統上使用這些文件名時,它確實工作正常。 – 2012-07-12 14:11:13

+0

@NaveedQamar請閱讀我的更新回答 – HatSoft 2012-07-12 14:26:46

2

看來,誤差不中「發生的CreateFile (字符串文件名1)「。如果是這樣,堆棧應該類似於:

... 
System.Convert.ToInt32(String value) 
e2erta.e2erta1.YourFtpClass.createFile(string filename1) <- I would expect this line! 
e2erta.e2erta1..ctor() 
+0

那麼你有什麼建議?它在我的電腦上工作正常。...... – 2012-07-12 14:20:33

+0

在「web.config」()上啓用調試信息。所以你可以看到錯誤發生的地方。 – Hailton 2012-07-12 14:24:45