FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUrl);
request.Method = WebRequestMethods.Ftp.ListDirectory;
var response = (FtpWebResponse)request.GetResponse();
Stream rStream = response.GetResponseStream();
StreamReader reader = new StreamReader(rStream);
string fileNames = reader.ReadToEnd();
List<string> ls = fileNames.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
for (int i = 0; i < ls.Count; i++)
Console.WriteLine(ls[i]);
This method only lists files present in the specified serverUrl directory . I want to list all the files of the FTP server. Can anyone suggest me anything?
I have written the related code in the msdn forum like: download each file in folder.
You can use the FtplistFile method to get a list of all files in the ftp server.
Here is a code example I modified.
Get file name:
Get file path in ftp: