473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to tell if FTP download successful?

Hi,

I am using this code to download files on VS 2005. It downloads the file but
waits until the timeout (which is why it is so short) to add the last 4
bytes or so. It always returns a WebException which most of the time is just
feedback from the FTP server, so how do I tell if the download was
successful/complete or not?

Tim

public void DownloadFile(string fileName, string mfgrId)
{
try
{
string destinationFile = @"C:\Program Files\MM\" + fileName;
FileInfo file = new FileInfo(destinationFile);
FileStream localfileStream;
FtpWebRequest request = WebRequest.Create("ftp://" + hostname + downloadDir
+ fileName) as FtpWebRequest;
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Timeout = 5000; //five seconds
if (file.Exists)
{
request.ContentOffset = file.Length;
localfileStream = new FileStream(destinationFile, FileMode.Append,
FileAccess.Write);
}
else
{
localfileStream = new FileStream(destinationFile, FileMode.Create,
FileAccess.Write);
}
WebResponse response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
byte[] buffer = new byte[1024];
int bytesRead = responseStream.Read(buffer, 0, 1024);
while (bytesRead != 0)
{
localfileStream.Write(buffer, 0, bytesRead);
bytesRead = responseStream.Read(buffer, 0, 1024);
}
localfileStream.Close();
responseStream.Close();
ErrorReporter.LogableError(fileName + " downloaded successfully",
ErrorReporter.ErrorTypes.DDS);
}
finally
{
}
}
Mar 13 '06 #1
0 1612

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: singh_chintu | last post by:
I have uploaded a file that is over 8MB and that is successful and I have verified that it is a successful upload. However, that same file seems to have a download limitation of 2MB which I...
3
by: Brent Billups | last post by:
I am trying to download files from one website to another for purposes of caching. In trying to do this, I created a VB dll component (using VB6), that used URLDownloadToFile, to allow me to...
0
by: Chuck Anderson | last post by:
I am writing a Php script to run on my home PC (Windows) that downloads an Apache access log file and inserts new entries into a database.. The only way I can access these log files is through a...
1
by: Tom | last post by:
Hi, I have a website providing pdf file downloading for registered member. Member needs to login and be able to download pdf file. I save pdf file in a directory. e.g....
4
by: Hitesh | last post by:
Hi, I am having a requirement where in user can click on a link and the download popup appears and then user should be redirected to a congratulations page. We didn't bother whether the...
5
by: sc48567189 | last post by:
Hello ! I need some help here. I google after the response but with no sucess. I need to download - randon size - parts of a file, not the whole file. Says: I have the zip file test.zip, it is 10...
0
by: bonita | last post by:
If I add the code for user to download the file (e.g. if(File.Exists(FILE_NAME)){......}), the ASP.NET will give the following timeout error: Timeout expired. The timeout period elapsed prior to...
1
by: a.r.austin | last post by:
Hello, I am trying to download a few files one after another from a remote server. Problem is that I don't know how to, or if I am able at all, set a time out for download. I don't want to time...
1
by: Tushman | last post by:
I'm a first time poster and know very little about programming. My situation is that I found a website (ImageFap) that has picture thumbnails. Of course in order to view them, you have to click on...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.