Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


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.

Error when I open a session


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 "" line :
Connection has been unexpectedly closed. Server sent command exit status 0.

My code is :

                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())
                    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 ?