Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
7.8k views
in .NET FTP by (200 points)
I have a small problem.

My program needs to be logged-on to the FTP server as long as my program runs.
Basicaly the program works fine but when i wait to long with sending FTP commands, the connection times-out.
When i send a new FTP request i get an IOException and a FTPException that indicate that the connection has timed-out but i want to know the connection status BEFORE i send any FTP command.

Is there a method for checking the connection status for example: logon or timeout?

Thans,
FJW.

10 Answers

0 votes
by (162k points)
I would consider doing what you need to and then calling quit() immediately. Whenever you have a new FTP request, login again and quit() when it is complete.

That's the best way of dealing with timeout problems.

I have a small problem.

My program needs to be logged-on to the FTP server as long as my program runs.
Basicaly the program works fine but when i wait to long with sending FTP commands, the connection times-out.
When i send a new FTP request i get an IOException and a FTPException that indicate that the connection has timed-out but i want to know the connection status BEFORE i send any FTP command.

Is there a method for checking the connection status for example: logon or timeout?

Thans,
FJW.
0 votes
by (200 points)
My idea was to make a program that logs on to the FTP server at startup and remains connected until the program is closed. My co-workers who will use the program tend to leave it running unnecesary.
Therefor i would like to visualize when the connection times-out, either by closing the program or by enabling a logon button.

FJW.
0 votes
by (162k points)
There's not really a way to detect a timeout other than getting an IOException when you try to run a command.

We'll look into providing a notification when a timeout occurs

My idea was to make a program that logs on to the FTP server at startup and remains connected until the program is closed. My co-workers who will use the program tend to leave it running unnecesary.
Therefor i would like to visualize when the connection times-out, either by closing the program or by enabling a logon button.

FJW.
0 votes
by (200 points)
I will modify my program slightly to detect the timeout via IOException.
I can always change it back when in the future i can chech the timeout / logon status or when a timeout event fires.

Thanks for your help,
FJW.
0 votes
by
hi. maybe you're interested in my solution for this problem...
i used threading to keep the gui usable, while operations are performed (ie transferring files)...
[connect]
while(true){
    noopTimer++;
    if(m_eventStop.WaitOne(0, true)){
        this.disconnect();
        m_eventStopped.Set();
        break;
    }
    [removed some things to keep it clear]
    if(noopTimer/100 == 1){ // every 10 sec.
        noopReply = this.ftp.Quote("NOOP", new string[1] {"200"});
        if(noopReply.StartsWith("200"))
            m_eventStop.Set();
        noopTimer = 0;
    }
    Thread.Sleep(100); // delay by 0.1 sec
}

maybe not the only-and-best solution, but it works.

hope it helps. :)
0 votes
by (580 points)
Where did you add this code to prevent timeouts? I can't add it after my call to UploadFile() because the thread locks until that command completes, and if I put it on a new connection in the code that creates the thread, wouldn't it perform the NOOP on a separate connection, which wouldn't help the ftp connection on the thread I'm interested in?
0 votes
by (162k points)
This is similar to how we are going to try to deal with timeouts - by inserting a NOOP during a transfer. However we will pause the transfer and send the NOOP periodically during the transfer.
0 votes
by (580 points)
Do you mean stopping the transfer, issuing a NOOP, and then resuming the transfer? Does that mean you will issue the NOOP on the transfer connection rather than the control connection? Doesn't the acknowledgement of the transfer completion come on the control connection, and if that is the connection that times out wouldn't it make more sense to issue the NOOP on the control connection? That way you also wouldn't be interrupting the file transfer to keep the control connection alive.

Do you have an idea where I would need to put the modification? I thought something inside the While loop in the PutBinary function in FTPClient.cs might do it:

   private void PutBinary(Stream srcStream, string remoteFile, bool append)
        {
...   
                while ((count = input.Read(buf, 0, buf.Length)) > 0 && !cancelTransfer)
                {
                    output.Write(buf, 0, count);
                    size += count;
                    monitorCount += count;
                    if (BytesTransferred != null && monitorCount > monitorInterval)
                    {
                        BytesTransferred(this, new BytesTransferredEventArgs(remoteFile, size));
                        monitorCount = 0;
                    }
                }
...
        }   
0 votes
by (162k points)
No, I mean doing it on the control connection - in the while loop after a certain number of seconds have passed. So it isn't interrupting the transfer as such - just doing it periodically while downloading.

Do you mean stopping the transfer, issuing a NOOP, and then resuming the transfer? Does that mean you will issue the NOOP on the transfer connection rather than the control connection? Doesn't the acknowledgement of the transfer completion come on the control connection, and if that is the connection that times out wouldn't it make more sense to issue the NOOP on the control connection? That way you also wouldn't be interrupting the file transfer to keep the control connection alive.

Do you have an idea where I would need to put the modification? I thought something inside the While loop in the PutBinary function in FTPClient.cs might do it:

0 votes
by (580 points)
See this post for an interim solution to the control connection timeout issue: http://www.enterprisedt.com/forums/viewtopic.php?p=3685#3685.

Categories

...