Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to download files from ftp server, its good while downloading when similar files are available in debug folder, if the similar file is not available in debug folder its skipping that file, can any one know about this problem

FtpWebRequest ftp;
                   ftp = (FtpWebRequest)FtpWebRequest.Create(new Uri(FTPAddress + file));
                   ftp.Credentials = new NetworkCredential(uID, pswrd);
                   ftp.KeepAlive = false;
                   ftp.Method = WebRequestMethods.Ftp.DownloadFile;
                   ftp.UseBinary = true;
                   ftp.Proxy = null;
                   ftp.UsePassive = false;
                   FtpWebResponse ftpR = (FtpWebResponse)ftp.GetResponse();
                   Stream responseStream = ftpR.GetResponseStream();
                   FileStream writeStream = new FileStream(".\\" + file, FileMode.Create);
                   int Length = 2048;
                   Byte[] buffer = new Byte[Length];
                   int bytesRead = responseStream.Read(buffer, 0, Length);
                   while (bytesRead > 0)
                   {
                       writeStream.Write(buffer, 0, bytesRead);
                       bytesRead = responseStream.Read(buffer, 0, Length);

                   }
Posted
Updated 13-Apr-13 4:22am
v2
Comments
OriginalGriff 13-Apr-13 10:13am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps if you post the code you are using to download it might help? Just the relevant fragments, please!
Use the "Improve question" widget to edit your question and provide better information.
Friendsaa 13-Apr-13 10:29am    
please check my updated question now

1 solution

I just tried your code (slightly changed to work with my ftp):
C#
string file = @"0eeeab9f-0587-461b-b966-f12c033e704a.thumb.jpg";
string strConnect = @"ftp://[MyUsername]:[MyPassword]@ftp.Images.[MyDomain].com/Images/" + file;
FtpWebRequest ftp;
ftp = (FtpWebRequest)FtpWebRequest.Create(strConnect);
ftp.KeepAlive = false;
ftp.Method = WebRequestMethods.Ftp.DownloadFile;
ftp.UseBinary = true;
ftp.Proxy = null;
ftp.UsePassive = false;
FtpWebResponse ftpR = (FtpWebResponse)ftp.GetResponse();
Stream responseStream = ftpR.GetResponseStream();
FileStream writeStream = new FileStream(".\\" + file, FileMode.Create);
int Length = 2048;
Byte[] buffer = new Byte[Length];
int bytesRead = responseStream.Read(buffer, 0, Length);
while (bytesRead > 0)
    {
    writeStream.Write(buffer, 0, bytesRead);
    bytesRead = responseStream.Read(buffer, 0, Length);
    }
(The site specific stuff is redacted and replaced with [...])

It works fine regardless of whether the file exists in the debug folder or not.

So what am I doing that you aren't, or vice versa?
 
Share this answer
 
Comments
Friendsaa 13-Apr-13 11:10am    
can u check your debug folder, is it downloaded, as i tried its not downloading till the same file is available in debug folder.
OriginalGriff 13-Apr-13 11:27am    
Yes.
Downloaded with just my normal exe files and no .jpg files in the folder at all. Looks fine in windows file viewer.
Delete it, place a different jpg file given the same name in the debug folder, run again. Downloaded ok, old file overwritten.

Works fine as far as I can see.
Friendsaa 13-Apr-13 12:15pm    
I want that jpg file to be download in debug folder, if the same file is already in debug folder its overwritten, if the same file is not in debug folder its not downloading? i want it in debug folder
OriginalGriff 13-Apr-13 12:31pm    
It works for me. What more can I say?
Have you tried single stepping it through the debugger?

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