0

I am trying to do a simple download of some files from an FTP server. I am using the .NET Assembly that WinSCP provides. The source FTP server has a setting that does not allow more than 3 sessions, so I need to disconnect once the files are downloaded. I am able to connect to the server, because every time I try to run the program 4 times, it disallows the session.open saying that the max sessions allowed is 3. Then I have to reboot the machine to end the sessions.

http://winscp.net/eng/docs/library_session_close

Am I doing something incorrectly? At this point I'm just trying to get the Connect and the Disconnect portion to work. I'm kinda new to this and would appreciate your help.

using System;
using WinSCP;

class FTPDownload2
{
    public static void Main()
    {
        // Setup session options
        SessionOptions sessionOptions = new SessionOptions
        {
            Protocol = Protocol.Ftp,
            HostName = "name",
            UserName = "uname",
            Password = "pwd!"
        };

        using (Session session = new Session())
        {
            // Connect
            session.Open(sessionOptions);
            session.Close();
        }
    }
}
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
KevAlert
  • 9
  • 2
  • Thanks Nimesh! neither Close(), Abort(), or Disconnect would work but the session.ExecuteCommand("quit") worked like a charm. Thanks again! – KevAlert Jan 16 '16 at 20:15
  • 2
    It's a bug in the server if it does not release resources for the session when the connection is closed without `QUIT` command. The [RFC 959](https://www.ietf.org/rfc/rfc959.txt) says in section 4.1.1. Access Control Commands: *"An unexpected close on the control connection will cause the server to **take the effective action of** an abort (`ABOR`) and **a logout (`QUIT`).**"* Most FTP clients do not send the `QUIT` command. – Martin Prikryl Jan 16 '16 at 20:20
  • I think you are correct this is an application server that supports FTP backup. It must either be a bug or a security setting to not allow more than three sessions in a given time frame. If I walk away and come back for 30 minutes, the sessions seem to be released. – KevAlert Jan 17 '16 at 00:05

0 Answers0