Welcome to the Xceed Community | Help
Community Search  
More Search Options

Closing connections problems.

Sort Posts: Previous Next
  •  11-25-2009, 12:34 AM Post no. 24978

    Closing connections problems.

    Hello there. I have been using the FTP product (3.7.8312.9580) for some time now without issue. Recently the company that I pull files from have limited the number of connections allowed at one time to 4. This has caused my code to stop working well. It seems that the connection is not being closed and on the 5th file pull I get a "no more connections allowed from this IP" error from the FTP server.

    Here is the basic original code that was pulling the files (note that there is actually a loop around this code for all of the files that need to be pulled).

                    using (FtpConnection connection = new FtpConnection(serverUri, userId, password))
                    {
                        FtpFile source = new FtpFile(connection, remoteDirectory + filename);
                        source.CopyTo(destination, true);
                    }

     

    So in order to try to solve the problem I added a bunch of things to the code.

                    using (FtpConnection connection = new FtpConnection(serverUri, userId, password))
                    {
                        connection.SendTelnetInterruptSignal = true;
                        connection.TraceWriter = new StringWriter();
                        try
                        {
                            connection.TestConnection();

                            FtpFile source = new FtpFile(connection, remoteDirectory + filename);
                            source.CopyTo(destination, true);
                        }
                        catch (Exception ex)
                        {
                            StringWriter stringWriter = (StringWriter)connection.TraceWriter;
                            logger.LogEvent(LogLevel.Normal, stringWriter.ToString());

                            throw ex;
                        }
                        finally
                        {
                            StringWriter stringWriter = (StringWriter)connection.TraceWriter;
                            logger.LogEvent(LogLevel.Debug, stringWriter.ToString());

                            connection.CloseConnections();
                            connection.Dispose();
                        }
                    }
     

    I did everything I could think of to close the connection and it did not work. Upon reading the TraceWriter output I was interested that no quit command was sent at the end of the communication. 

    I was also interested that the connection.TestConnection() made things much worse as it seemed to crate it's own connection using up another precious connection and not releasing it.

     What is it that I am missing to close out these connections? Or is it simply something screwy with the server?

     

    Thanks for your attention on this...

     

    Mark,

  •  12-02-2009, 4:48 PM Post no. 25063 in reply to 24978

    Re: Closing connections problems.

    Hi Mark,

    Normally I always start by recommending to upgrade to the latest version (4.1 in this case), however in your scenario I don't think it's going to solve the problem. It's still good to get the latest bug fixes though.

    You will not be able to do this directly, as FtpConnection manages all the connections under the hood and will take care of recycling the connections. It's also possible that it keeps multiple connections open until it is done with all its transfers.

    The best solution in your case would be to use FtpClient instead and do everything manually. It kills the fact that right now the FileSystem does everything for you, however it gives you control over all your connections.

     


    Diane Lafontaine
    Technical Support / Technical Support Team Lead
    Xceed Software Inc.
  •  12-03-2009, 12:04 AM Post no. 25064 in reply to 25063

    Re: Closing connections problems.

    Yaaaay, code rewrite. That's always fun. ;-)

    Anyhoo. As a feature in the next release, would it make sense to throw a 'quit' command in at the end of the connection to make sure that is closed?

    Just a thought...

     

    Thanks for the reply though.

     

    Mark,

  •  12-15-2009, 5:32 PM Post no. 25217 in reply to 25064

    Re: Closing connections problems.

    Hi Mark,

    Closing an ftp connection is not always as trivial as it should be. 

    Among other things, the origin of your problem could be coming from the ftp server.  As a matter of fact, there is usually a "recycle" that occurs on the ftp server when a connection occurs.  During this time (specified by the parameter TIME_WAIT on the server, but at the operating system level, normally), this can lead into troubles. 

    From this site http://www.ncftp.com/ncftpd/doc/misc/ftp_and_firewalls.html we learn that :

    The FTP specifies a mechanism for a default data connection, where the server can connect back to the client from port 20 to the same IP address and port number that the client is originating from on the control connection.  However, it really isn't feasible because the preferred transfer mode is "stream mode" and would require that the default data connection be reopened with each data transfer (and TCP won't let you do that until TIME_WAIT expires on the previous default data connection that has the same connection endpoints).

    What you could try is to transfer a lot of files using FileZilla (freeware, http://filezilla-project.org/download.php?type=client ) while setting the maximum number of the data connections to four and see how things go.  It is probably the best way to determine if your problem is coming from the ftp server or from somewhere else.

    Best regards,


    Ghislain
    Technical Support and software developer
    Xceed Software Inc.
    Knowledge Base : http://xceed.com/kb/
    Update Center : http://xceed.com/updates/
    Documentation Center : http://xceed.com/doc/
    For everything else, there is Google
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.