Download file problem

May 29, 2012 at 8:52 AM
Edited May 31, 2012 at 4:59 PM

Dear all, I'm using this library to connect a windows service to a control unit via FTP to download some files. The control unit has the FTP Server and my application is the FTP Client.

I have no problem to start the connection but sometimes I have problem with the download, my application is blocked in the Channel.Read function(), no timeout will expire. As an example that I found, I implemented the following block of code:

try
{
    long size = ftp.GetFileSize(file_name);

    using (FtpDataStream chan = ftp.OpenRead(file_name))
    {
        byte[] buf = new byte[ftp.ReceiveBufferSize];
        int read = 0;
        long total = 0;
        FileStream downloading_file = new FileStream(local_file_name, FileMode.Create, FileAccess.Write, FileShare.Read);

        while ((read = chan.Read(buf, 0, buf.Length)) > 0)
        {
            total += read;

            downloading_file.Write(buf, 0, read);

            log(String.Format("\nDownloading: {0}/{1} {2:p2}", total, size, ((double)total / (double)size)));
        }
    }

    log("*** File Downloaded ***");
}
catch ...

log() is a function to save in a file what happen.

The problem is that the control unit is not stable and the connection could be lost during the download. Using the log I can assume that the Read function is blocking and no timeout will be expired. For example in the log file I see:

Downloading 1000/10000 10%
Downloading 2000/10000 20%
Downloading 3000/10000 30%
Downloading 4000/10000 40%

and nothing for more than 30 minutes, than I stopped the application...

I don't know how to set a timeout.

Could you help me? I tried to insert ReadTimeOut = 2000 but it seems not working.

Alessio

May 31, 2012 at 5:02 PM

Is there someone who could help me?

Coordinator
May 31, 2012 at 10:20 PM
I will take a look into the matter as soon as possible. I thought we
had added time outs already.

On Thu, May 31, 2012 at 11:02 AM, Alex_li <notifications@codeplex.com> wrote:
> From: Alex_li
>
> Is there someone who could help me?
>
> Read the full discussion online.
>
> To add a post to this discussion, reply to this email
> ([email removed])
>
> To start a new discussion for this project, email
> [email removed]
>
> You are receiving this email because you subscribed to this discussion on
> CodePlex. You can unsubscribe or change your settings on codePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any posts
> to this discussion will also be available online at codeplex.com
Coordinator
Jun 12, 2012 at 5:54 AM

Alex_li, I apologize for the long delay in getting around to working on this but I've changed FtpDataStream so that it honors the ReadTimeout settings and I've added a new property FtpControlChannel/FtpClient called DataChannelReadTimeout which sets the ReadTimeout on all new data streams opened from the control connection.

Jun 12, 2012 at 7:46 AM

Ok, thank you very much for your support.