I want to fetch the files from folder through FTP using c#, I have folder name called MyFolder, inside of this folder i have multiple folder, i need to fetch each file from all this folders which is inside the my MyFolder.Below code which i am getting all directories,Now i need to get each file.
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();
}