Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
406 views
in .NET FTP by (150 points)
I need to send off files to any of several endpoints (by SFTP),  as they become available. Right now, I'm opening a new FTP connection each time I'm ready to send, but this is not a good use of the connection, and eventually bogs my server down. Is there a pool manager, which would give me the already-open connection to a given endpoint, or open a new one if needed?

1 Answer

0 votes
by (161k points)
selected by
 
Best answer
How often do you need to send files? Typically, SFTP servers will disconnect a connection if it is idle for more than a few minutes, so if it is more than say two minutes between sends, you should disconnect and reconnect each time.
by (150 points)
I have hundreds of files coming in over a short time period, so it seems like I want to keep the connection open.

It's possible I am doing something else wrong, and that opening new connections is not the reason I am seeing performance issues.  My code looks roughly like this (error handling omitted):

        public void SendFile(Stream fileStream, string filename)
    {
           var client = new SSHFTPClient() { .... };

            client.CloseStreamsAfterTransfer = true;

        ... authentication stuff omitted ....

            client.Connect();

        client.ChDir(config.ServerPath);

        client.Put(fileStream, filename);
       }

I'm assuming that CloseStreamsAfterTransfer handles closing the connection. Is that correct?
by (161k points)
You need to call Close() to close the connection.

But this probably isn't the way to do it if you have lots of files coming in in a short time period.

I don't know how you kick off the program, but I would read a list of all the files you have available, connect, transfer the files and then disconnect - NOT a new connection each file. The next time the program is launched do the same thing.
by (150 points)
I figured I should call Close, but it's not obvious how to do that.  The SSHFTPClient class does not have a close method.  Can you provide an example of closing the connection?

It sounds like I will have to manage the pool of connections to different endpoints on my own if I want to dispatch files to different locations as they arrive.
by (2.7k points)
The method to close the connection is called Quit(), matching the equivalent command in command-line FTP.

Yes, the inbuilt connection pool doesn't handle multiple destinations.

Categories

...