Niranjan Poddar

Niranjan Poddar

  • 1.5k
  • 583
  • 72.6k

Get Files from a Remote Server using ftp.

Jun 6 2016 8:22 AM
Dear all,
 Please help me how to get all files name from remote server using ftp.
 
 
 I have already used but getting error:
public List<string> GetFileList()
{
 
System.Net.FtpWebRequest ftpRequest = (System.Net.FtpWebRequest)System.Net.WebRequest.Create("ftp://ftpserver.com");
ftpRequest.Credentials = new System.Net.NetworkCredential("username", "password");
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
System.Net.FtpWebResponse response = (System.Net.FtpWebResponse)ftpRequest.GetResponse();
System.IO.StreamReader streamReader = new System.IO.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();
return directories;
}
 
 Error: The remote server returned an error: (500) Internal Server Error.
 
Thanks & Regards
Niranjan Poddar 
 
 
 
 

Answers (1)