.NET Server sent command exit status 0

Advertisement

d4_david
Joined:
Posts:
4
Location:
Prague

.NET Server sent command exit status 0

Hi,
I am newbie at WinSCP, but this task have been assigned to me:
1) Create app to upload files via SFTP
but problem is:
1) Form WinSCP application already works and host name, user name etc. are correctly set
2) But when I want to create my application I am receiving this error:
Error: WinSCP.SessionRemoteException: Connection has been unexpectedly closed. Server sent command exit status 0.
Then there is a stack trace with Authentication failed error.

This is code I use:
try
            {
                // Setup session options
                SessionOptions sessionOptions = new SessionOptions
                {
                    Protocol = Protocol.Sftp,
                    HostName = "190.56.75.08",
                    UserName = "globus",
                    //Password = "",
                    SshHostKeyFingerprint = "ssh-rsa 1536 1f:00:35:19:90:82:ec:b4:1d:18:2f:fe:df:65:da:12",
                    SshPrivateKeyPath = @"C:\keys\privatekey.ppk"             
                };

                using (Session session = new Session())
                {
                    // Connect
                    Console.WriteLine("Trying to connect...");
                    session.Open(sessionOptions);
                    Console.WriteLine("Connected.");
                    Console.WriteLine("");

                    // Upload files
                    Console.WriteLine("Trying to upload files...");
                    TransferOptions transferOptions = new TransferOptions();
                    transferOptions.TransferMode = TransferMode.Binary;

                    TransferOperationResult transferResult;
                    transferResult = session.PutFiles(@"C:\winscp515\test.xml", "/batches/in", false, transferOptions);
                    Console.WriteLine("Uploaded.");

                    Console.WriteLine("Check transfer result...");
                    // Throw on any error
                    transferResult.Check();
                    Console.WriteLine("Checked.");
                    Console.WriteLine("");

                    // Print results
                    foreach (TransferEventArgs transfer in transferResult.Transfers)
                    {
                        Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
                    }
                }

                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: {0}", e);
                return false;
            }

I would guess that problem is somewhere in the code because the form application works fine.
Thanks for any help. As I said I am really newbie in this and I am kind a lost here...

Reply with quote

Advertisement

d4_david
Joined:
Posts:
4
Location:
Prague

Re: .NET Server sent command exit status 0

I have enabled logging and everything seems fine except the part where the public key signature is sent.

Client log:
. 2013-06-26 08:50:14.799 Reading private key file "C:\keys\privatekey.ppk"
! 2013-06-26 08:50:14.799 Using username "globus".
. 2013-06-26 08:50:14.845 Offered public key
. 2013-06-26 08:50:14.869 Offer of public key accepted
! 2013-06-26 08:50:14.869 Authenticating with public key "rsa-key-16130608"
. 2013-06-26 08:50:14.891 Prompt (3, SSH key passphrase, , Passphrase for key "rsa-key-16130608": )
. 2013-06-26 08:50:22.677 Sent public key signature
. 2013-06-26 08:50:22.691 Access granted
. 2013-06-26 08:50:22.695 Opened channel for session
. 2013-06-26 08:50:22.761 Started a shell/command

App log:
. 2013-06-26 10:42:20.791 Reading private key file "C:\keys\privatekey.ppk"
! 2013-06-26 10:42:20.791 Using username "globus".
. 2013-06-26 10:42:20.797 Offered public key
. 2013-06-26 10:42:20.817 Offer of public key accepted
! 2013-06-26 10:42:20.817 Authenticating with public key "rsa-key-16130608"
. 2013-06-26 10:42:20.817 Prompt (3, SSH key passphrase, , Passphrase for key "rsa-key-16130608": )
. 2013-06-26 10:42:20.817 Disconnected: Unable to authenticate

So I really don't know what to do now.... Any help?

Reply with quote

d4_david
Joined:
Posts:
4
Location:
Prague

Re: .NET Server sent command exit status 0

Finaly I found solution :)

This post was really useful and led me to achieve my goal : https://winscp.net/forum/viewtopic.php?t=11807

So I used Pageant https://winscp.net/eng/docs/ui_pageant and since then the app worked fine. The problem was that after closing the Pageant all added keys were deleted from the list. You can run Pageant using command line and use parameter to define the location of your keys https://blog.shvetsov.com/2010/03/making-pageant-automatically-load-keys.html
After this another problem may occur and if the keys are stored encrypted, Pageant will request the passphrases on startup, otherwise they'll be loaded without any prompts. Unfortunately may key was encrypted and you can't just pass passphrase to the command line. Another post was helpful with this issue https://superuser.com/questions/367531/getting-pageant-to-save-keys-files. You just have to open your key in PuTTYgen and save it again without password. Then everything works like a charm ;)[/url]

Reply with quote

Advertisement

You can post new topics in this forum