This project is read-only.

SFTP connection problem - Timeout

Sep 13, 2013 at 5:26 PM
I am having a problem with a simple sftp file transfer. I am starting to wonder if there is a problem when I change the port from standard 22 to a custom port of 5929. I can connect to the remote server using putty and Winscp using port 5929. My application will connect to my local Linux machine (CENTOS) using port 22 without a problem. However, when I try to use the application to connect to the remote server on port 5929 it times out and the log does not show that there was an attempt.

Any ideas?

Note: This is a test program, the idea is to use a configuration file for the data.

const int port = 5929;
        const string host = "****";
        const string userName = "******";
        const string password = "***";
        const string workingdirectory = "/";
        const string uploadfile = @"c:/Projects/test/HCCS.txt";


        var keyboardAuthMethod = new KeyboardInteractiveAuthenticationMethod(userName);

        keyboardAuthMethod.AuthenticationPrompt += delegate(Object senderObject, AuthenticationPromptEventArgs eventArgs)
        {
            foreach (var prompt in eventArgs.Prompts)
            {

                if (prompt.Request.Equals("Password: ", StringComparison.InvariantCultureIgnoreCase))
                {
                    prompt.Response = password;

                }

            }

        };

        var passwordAuthMethod = new PasswordAuthenticationMethod(userName, password);

        var connectInfo = new ConnectionInfo(host, userName, passwordAuthMethod, keyboardAuthMethod);


        Console.WriteLine("Creating client and connecting");
        Console.WriteLine(host);

        using (SftpClient client = new SftpClient(connectInfo))
        {
            try
            {
                client.OperationTimeout = new TimeSpan(0, 0, 30);
                client.Connect();
            }
            catch (Exception exe)
            {
                Console.WriteLine(exe.ToString());
            }
            if (client.IsConnected)
            {
                Console.WriteLine("Connected to {0}", host);
                var ls = client.ListDirectory(".");
                foreach (var s in ls)
                {
                    Console.WriteLine(s);
                }
            }
            else
                Console.Write("Not Connected");


            Console.Read();
Sep 13, 2013 at 10:43 PM
You don't use your "const int port = 5929;" anywhere.
Sep 13, 2013 at 11:15 PM
Aha...I had been messing with so much trying to get the authentication all figured out which was interesting but fun... the examples that I had been using all worked on port 22 I added the port cont into the connectInfo and it worked first time

da_rinkes -thanks for the extra set of eyes...appreciate it ..
dave