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,