2017-09-11 12 views
0

私はFTP経由で一つのフォルダ内のすべてのファイルを一覧表示しようとするドットを受け取る:C#は唯一

FtpWebRequest reqFTP; 
//uri string - webhost.com/public_html/some_dir/myfolder 
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + remoteDir + "/" + folder)); 
reqFTP.UseBinary = true; 
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword); 
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory; 
reqFTP.Proxy = null; 
reqFTP.KeepAlive = false; 
reqFTP.UsePassive = false; 
reqFTP.Timeout = 300000;//wait for 5 min 

response = reqFTP.GetResponse(); 

reader = new StreamReader(response.GetResponseStream()); 
string line = reader.ReadLine(); 

    while (line != null) //line is always '.' here 
    { 
     if(line.Length > 3) 
     { 
      line = line.Split('/')[1]; 
      result.Append(line); 
      result.Append("\n"); 
      line = reader.ReadLine(); 
     } 

    } 

接続はOKと思われる、私のresponse取得:

StatusDescription 150 Connecting to port 50058\r\n 
WelcomeMessage 230 OK. Current restricted directory is /\r\n 

しかし、問題を私がlineを読むと、それは常に1つのドットです。したがって、whileループは無限になります。

別のサーバーに接続しようとしましたが正常に動作しています。 私は助言をいただきたいと思います。

答えて

0

通常、ディレクトリの最初のエントリは、. = "this"ディレクトリへの参照です。

あなたが決して到達しないifブロック内の次のエントリだけを読んでも、それは決して合格しません。

コードは次のようにする必要があります:line.Length > 3条件が独自に疑わしいようだけど

while (line != null) 
{ 
    if (line.Length > 3) 
    { 
     line = line.Split('/')[1]; 
     result.Append(line); 
     result.Append("\n"); 
    } 

    line = reader.ReadLine(); 
} 

。しかしそれは別の質問です。

+0

ありがとうございました。 –