Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello every one i jus want to download multiple files from ftp server to local machine
and i want to download only updated data from ftp server to local folder
Posted
Comments
Abdul Quader Mamun 14-Jul-12 10:20am    
Have you tried anything with the code? and describe your question clearly.
abhilash yelmelwar 17-Jul-12 1:55am    
i want to download multiple files from ftp server to local folder....
FtpWebRequest reqFTP;
try
{
//filePath = <<The full path where the file is to be created.>>,
//fileName = <<Name of the file to be created(Need not be the name of the file on FTP server).>>
FileStream outputStream = new FileStream(filePath + "\\" + fileName, FileMode.Create);

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + txtip + "/" + fileName));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
//reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(txtuser.Text.ToString(), txtpass.Text.ToString());
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
int bufferSize = 2097151;
int readCount;
byte[] buffer = new byte[bufferSize];

readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}

ftpStream.Close();
outputStream.Close();
response.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}


private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog fldDlg = new FolderBrowserDialog();
if (txtupload.Text.Trim().Length > 0)
{
if (fldDlg.ShowDialog() == DialogResult.OK)
{
Download(fldDlg.SelectedPath, txtupload.Text.Trim());
}
}
else
{
MessageBox.Show("Please enter the File name to download");
}

}
i tried with the above code but only single file is downloading i need to download multiple files....

Steps.
1. Determine how you will determine whether is is "updated" or not. Presumably via file time.
2. Get a FTP GUI client.
a. Insure that you can connect to the target FTP server.
b. Insure that you can see the update data (like file time.)
3. Get a FTP client library or write one.
4. Using 3 write code that does FTP steps. It will be similar to what you did via the GUI. Make sure that you check for and report error values.
 
Share this answer
 
Comments
abhilash yelmelwar 17-Jul-12 1:59am    
yes im agree with u...we can download updated file using time
can u pls give me example?? or any link...
Step 3. Get a FTP client library or write one.

The last time I looked for a FTP solution for C# it required purchasing a library from a 3rd party vendor (I could have written one.)

An "example" requires writing to a specific API, which requires having the library in the first place.

And as I stated you need to do Step 2 first which isn't something that anyone else can do for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900