Error when I open a session

Advertisement

BlackAlpha
Joined:
Posts:
1
Location:
Reunion Island

Error when I open a session

Hello,

I want to connect to a SFTP to upload a file with C# and WinScp but i'm having a problem, i got this error ah the "session.open()" line :
Connection has been unexpectedly closed. Server sent command exit status 0.


My code is :
try
            {
                var sessionsOptions = new SessionOptions
                {
                    Protocol = Protocol.Sftp,
                    HostName = Settings.Default.p_credHost,
                    UserName = Settings.Default.p_credName,
                    Password = Settings.Default.p_credPass,
                    PortNumber = 22,
                    GiveUpSecurityAndAcceptAnySshHostKey = true
                };

                using (var session = new Session())
                {
                    session.Open(sessionsOptions);
                    var transferOptions = new TransferOptions {TransferMode = TransferMode.Binary};

                    session.PutFiles(localFile, string.Concat("/", newFile), true, transferOptions);
                }

            }
            catch (SessionException error)
            {
                MessageBox.Show(string.Concat("FTP Error : ", error.Message));
            }

Even if I set an SSH key, I still get the same error, do you have an idea why ?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Error when I open a session

Are you able to connect with any (even GUI) SFTP/SSH client?

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

Advertisement

You can post new topics in this forum