Varshini S
asked on
c# download files from ftp
I am creating a application in c# to download files from ftp and copy in my local computer.
If download folder contains directory i need create a same folder in my local computer and down load all the files from same folder.
i am using the following code for this. This is works fine when down folder does not contains any directory. i do not know how to fetch the all directory name from ftp directory and create the same folder in my local drive. Please let me know how to achieve this ?
private void button2_Click(object sender, EventArgs e)
{
ftpDirectory = FtpServerName.ToString() + FtpPath.ToString();
FtpWebRequest request = (FtpWebRequest)WebRequest. Create(ftp Directory) ;
request.Credentials = new NetworkCredential(FtpUserN ame.ToStri ng(), FtpPassword.ToString());
request.Method = WebRequestMethods.Ftp.ListDirectory;
StreamReader streamReader = new StreamReader(request.GetRe sponse().G etResponse Stream());
string fileName = "";
while (fileName != null)
{
fileName = streamReader.ReadLine();
if (fileName != null)
{
string downLoadStatus = Download(FtpServerName.ToS tring(),
FtpPath.ToString(), fileName, localPath,
FtpUserName.ToString(), FtpPassword.ToString());
}
}
request = null;
streamReader = null;
}
If download folder contains directory i need create a same folder in my local computer and down load all the files from same folder.
i am using the following code for this. This is works fine when down folder does not contains any directory. i do not know how to fetch the all directory name from ftp directory and create the same folder in my local drive. Please let me know how to achieve this ?
private void button2_Click(object sender, EventArgs e)
{
ftpDirectory = FtpServerName.ToString() + FtpPath.ToString();
FtpWebRequest request = (FtpWebRequest)WebRequest.
request.Credentials = new NetworkCredential(FtpUserN
request.Method = WebRequestMethods.Ftp.ListDirectory;
StreamReader streamReader = new StreamReader(request.GetRe
string fileName = "";
while (fileName != null)
{
fileName = streamReader.ReadLine();
if (fileName != null)
{
string downLoadStatus = Download(FtpServerName.ToS
FtpPath.ToString(), fileName, localPath,
FtpUserName.ToString(), FtpPassword.ToString());
}
}
request = null;
streamReader = null;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER