Topic ".NET Specifiy Initial Remote Directory"

Author Message
peter594

Guest


Hello,

I currently try to get an SFTP connection to work with the .NET Assembly.
What I do is the following (see code). But I can't get this to work. I should mention I have no read or write permissions to the root directory only to a directory called /OUT. But I haven't found any possiblity to specify the Initial Remote directory before session.Open. Has anyone a hint for me about this issue?

The session.Open(sessionOptions) throws following expection:
An unhandled exception of type 'WinSCP.SessionRemoteException' occurred in WinSCPnet.dll

Additional information: Connection has been unexpectedly closed. Server sent command exit status 0. Authentication failed.
The thing is a generated this information with Winscp Windows program and the settings are right. I also added the password which is not added by default in generated code.
I can connect by commmand line of Winscp and with Winscp GUI so the settings should be correct.

Code:

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var sessionOptions = new SessionOptions
            {
                Protocol = Protocol.Sftp,
                HostName = "...",
                UserName = "...",
                Password = "...",
                SshHostKeyFingerprint = "...",
                SshPrivateKeyPath = @"FILE",
            };


            using (Session session = new Session())
            {
                // Connect

                sessionOptions.AddRawSettings("AuthGSSAPI", "...");
                sessionOptions.AddRawSettings("Cipher", "...");
                sessionOptions.AddRawSettings("KEX", "...");
                session.Open(sessionOptions);
                var result = session.ListDirectory("/OUT");
            }
        }
    }
}
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session 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.
peter594

Guest


Hello Martin,

first thanks for your answer. Enclosed the requested log, I removed all the personal information like URL, usernames etc. At says Disconnected: Unable to authenticate at the end but the login informations are exactly the same like when I enter it into the normal GUI. There it can connect. The only difference is in the GUI I also private in the Directory options a remote directory name.
log.txt (6.74 KB) Private file

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
Your private key is encrypted. You have to provide the passphrase using Session.Passphrase, or re-save the key unencrypted.

See https://winscp.net/eng/docs/faq_passphrase
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License