简体   繁体   中英

How to get file list from specific folder from remote server in C#?

I want to get list of files from specific folder of the remote server. Currently, I can get list of files and folder using following code. There is a folder "SoftwareUpdate" in this list. I want to get file list of "SoftwareUpdate" folder.

Here is my current code:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftp.abc.com/");
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("testuser", "test123");
FtpWebResponse response = (FtpWebResponse)request.GetResponse();

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

while (!reader.EndOfStream)
{
    String filename = reader.ReadLine();
}

Can anybody suggest me how to get list of files of specific folder?

只需将第一行更改为...

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftp.abc.com/SoftwareUpdate/");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM