Steps to download a file from a FTP:
- Create a FTP web request.
- Create an output File stream to select the destination of the file to store.
- Get the response from the request.
- Write the reponses to the output file stream.
- Now the file is downloaded from the FTP path and placed in the specified path.
Used Namespaces:
using System.Net;
using System.IO;
Step 1: Usage:
FTPDownload("C:\\", "default.aspx", "ftp://208.43.121.51/", "UserName", "Password");
Creating NetworkCredential means passing the username and password of the FTP path:
/// <summary>
/// NetworkCredential just to set the User and password of ftp path.
/// </summary>
public static NetworkCredential CreateNetworkCredentials(string ftpUserID, string ftpPassword)
{
return new NetworkCredential(ftpUserID, ftpPassword);
}
Step 2: Creating a FTP web Request.
/// <summary>
///Creates the FTP web request
/// </summary>
public static FtpWebRequest CreateFTPRequest(string fullFtpPath, string fileName)
{
return (FtpWebRequest)FtpWebRequest.Create(new Uri(fullFtpPath + "/" + fileName));
}
Step 3: Download a file from a FTP path and store in a local folder.
//Helps to download file from FTP and save it to local folder.
public static void FTPDownload(string path, string fileName, string fullFtpPath,
string ftpUserID, string ftpPassword)
{
FileStream outputStream;
//Now the FTP web request completed and ready for response.
FtpWebRequest ftpWebRequest = GetDownloadFTPWebRequest(path, fileName, fullFtpPath, ftpUserID, ftpPassword, out outputStream);
//Getting response from the request.
FtpWebResponse response = (FtpWebResponse)ftpWebRequest.GetResponse();
PassFileStreamDataToStream(response, outputStream);
}Step 4: Setting the web request and returning it.
//Download
public static FtpWebRequest GetDownloadFTPWebRequest(string path, string fileName, string fullFtpPath,
string ftpUserID, string ftpPassword, out FileStream fs)
{
//Creates file stream based on the passed path.

narasappa JPosted Nov 17, 2017, 5:19 AM
Is it possible to show a progress bar on download.
Abhineet SrivastavaPosted Apr 4, 2014, 8:51 AM
Kindly suggest
Abhineet SrivastavaPosted Apr 4, 2014, 8:51 AM
is it possible that we pass the HOst,User Name ,Passowrd n get the Folder afterthat we select the folder which will download to folder?
Abhineet SrivastavaPosted Apr 4, 2014, 8:48 AM
Where is Host details ,Local folder details where file would be download.... Means if i have to make it dynamic(By Putting Host,Credinatial)