2017-11-04 41 views
0

C#を使用してFTP経由でFTPからファイルを取得したいのですが、というフォルダ名がありますMyFolder、このフォルダの中に複数のフォルダがあります。私の内部にあるこのすべてのフォルダMyFolder。私はすべてのディレクトリを取得しているコード、今私は各ファイルを取得する必要があります。フォルダからFTP経由でファイルを取得するにはC#

Eg:httpdocs/Myfolder/newfolder/newfile.txt 
           /newfile1.txt 
           /newfile2.txt 
    httpdocs/Myfolder/newfolder1/newfile.txt 
    httpdocs/Myfolder/newfolder2/newfile.txt 


     FtpWebRequest ftpRequest =(FtpWebRequest)WebRequest.Create("ftp://www.xxxxxxx.com/httpdocs/MyFolder"); 
     ftpRequest.Credentials = new NetworkCredential("xxxxx", "xxxxxx"); 
     ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory; 
     FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse(); 
     StreamReader streamReader = new StreamReader(response.GetResponseStream()); 

     List<string> directories = new List<string>(); 

     string line = streamReader.ReadLine(); 
     while (!string.IsNullOrEmpty(line)) 
     { 
      directories.Add(line); 
      line = streamReader.ReadLine(); 
     } 
     streamReader.Close(); 
    } 

答えて

-1

MSDNのドキュメントをご覧ください。 https://msdn.microsoft.com/de-de/library/ms229711(v=vs.110).aspx

public static void Main() 
    { 
     // Get the object used to communicate with the server. 
     FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm"); 
     request.Method = WebRequestMethods.Ftp.DownloadFile; 

     // This example assumes the FTP site uses anonymous logon. 
     request.Credentials = new NetworkCredential ("anonymous","[email protected]"); 

     FtpWebResponse response = (FtpWebResponse)request.GetResponse(); 

     Stream responseStream = response.GetResponseStream(); 
     StreamReader reader = new StreamReader(responseStream); 
     Console.WriteLine(reader.ReadToEnd()); 

     Console.WriteLine("Download Complete, status {0}", response.StatusDescription); 

     reader.Close(); 
     response.Close(); 
    } 

編集 :Already on StackOverflowはここを見てください。

関連する問題