2017/02/14

C#.Net 透過FtpWebRequest取得FTP檔案清單


執行結果:



Code:
var request = (FtpWebRequest)WebRequest.Create("FTP URL");
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
request.Credentials = new NetworkCredential("user", "password");
try
{
    var response = (FtpWebResponse)request.GetResponse();
    using (var stream = new StreamReader(response.GetResponseStream()))
    {
        var list = stream.ReadToEnd();
        Console.WriteLine(list);
    }
}
catch (WebException ex)
{

}

沒有留言:

張貼留言