FTP download stops just short...

T

Tim Cowan

Hi,

I am trying to download a 3MB file from an MS FTP server. Below is the code.
Everything works fine, it starts the download and gets to with a couple of
thousand bytes and then just hangs and eventually times out. It happens with
4MB files too. Small files under 100k work just fine. I haven't tested much
in between .

If I connect using a simple FTP client it works just fine and downloads the
file. I have no idea why it will not finish the download. I am using VS 2005
on Win XP.

Can someone help?

Tim

public bool DownloadFile(string fileName, string mfgrId)
{
try
{
Uri uri = new Uri("ftp://" + hostname + downloadDir + fileName);
FtpWebRequest request = WebRequest.Create(uri) as FtpWebRequest;
request.Credentials = GetCredentials();
ftp = request;
ftp.Method = WebRequestMethods.Ftp.DownloadFile;
ftp.KeepAlive = false;
ftp.UseBinary = true; //true binary false text
ftp.UsePassive = true;
using (WebResponse response = ftp.GetResponse())
using (BinaryReader reader = new BinaryReader(response.GetResponseStream()))
using (BinaryWriter writer = new BinaryWriter(File.Open(@"C:\Program
Files\MarginMate\" + fileName, FileMode.Create)))
{
byte[] buffer = new byte[2048];
int count = reader.Read(buffer, 0, buffer.Length);
while (count != 0)
{
writer.Write(buffer, 0, count);
count = reader.Read(buffer, 0, buffer.Length);
}
}

ErrorReporter.LogableError(fileName + " downloaded successfully.",
ErrorReporter.ErrorTypes.DDS);
return true;
}
catch (Exception e)
{
ErrorReporter.LogableError("Failed to download file: " +
e.Message.ToString(), ErrorReporter.ErrorTypes.DDS);
return false;
}
}
 
R

rowan

I know that MS added some lock down features in IIS 6.0 that might have
something to do with it. I've hit it in uploading files larger than
2mg.
What I found was that in C:\Windows\System32\inetsrv\MetaBase.xlm.

Make a backup before modifing anything. You will have to stop and
start all IIS services for it to take effect, or reboot.

In my case there was a value called AspMaxRequestEntityAllowed which I
changed from the 2mg value to 1073741824 (roughly 1gb).

There might be limits on the ftp server similiar to those on the IIS
server. I hope this points you in the right direction.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top