Topic "VB.Net - Cannot Open Session"

Author Message
kelvintan
[View user's profile]

Joined: 2014-04-10
Posts: 1
Location: Singapore
Hi,

I have been trying to write a method to connect to the server using the local machine private key file to the sFTP server. I can connect successfully using the WinSCP GUI.

Following are my codes. During the debug mode, it always stop at the session.open line and there isn't any useful error message given.

Code:

  Try
            Dim sessionOptions As New SessionOptions

            With sessionOptions
                .Protocol = Protocol.Sftp
                .HostName = "xxx.xxx.xxx.xxx"
                .UserName = "xxxxx"
                .PortNumber = "22"
                .SshHostKeyFingerprint = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
                .SshPrivateKeyPath = "x:\xxxx\xxxx.ppk"
            End With

            Using Session As Session = New Session
                Session.DisableVersionCheck = True
                Session.SessionLogPath = "D:\sftplog.log"

                ' Connect
                Session.Open(SessionOptions)

                Dim transferOptions As New TransferOptions
                transferOptions.TransferMode = TransferMode.Binary

                Dim transferResult As TransferOperationResult
                transferResult = Session.PutFiles("D:\Outbox\*", "/upload/xxxx/", False, transferOptions)

                ' Throw on any error
                transferResult.Check()

                ' Print results
                Dim transfer As TransferEventArgs
                For Each transfer In transferResult.Transfers
                    Console.WriteLine("Upload of {0} succeeded", transfer.FileName)
                Next
            End Using

            Return 0
        Catch e As Exception
            Console.WriteLine("Error: {0}", e)
            Return 1
  End Try


Any help or tips would be greatly appreciated.

Thank you.
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Please attach the session log file.
_________________
Martin Prikryl
Bozo
[View user's profile]

Joined: 2014-05-03
Posts: 3
Location: Nowhere
Hi,

I am new to this forum, and was wondering if this has been resolved? I am having the same problem and have been looks for some time to resolve this. Below is my code. I tried to get a session log, but it never gets connected so there is not one. This error on the open statement. This is written in VB .NET 2010 Express.

One more thing, I wrote a VB Console app to execute the WinSCP that used a script file and work worked perfectly. The only issue I had with this method was lack of visibility and control of what may happen in an error situation. So I know all Of the parameters and Public key work.

[code]
Dim sftpOptions As New SessionOptions

With sftpOptions
.Protocol = Protocol.Sftp
.HostName = "xxx.xxx.xxx.xxx"
.UserName = "UserName"
.SshPrivateKeyPath = "C:\FTPFolder\Code\Test.ppk"
.PortNumber = 443
End With

Using sftp As Session = New Session
sftp.SessionLogPath = "C:\FTPFolder\Code\sftplog.log"
sftp.ExecutablePath = "C:\FTPFolder\Code\WinSCP.exe"
sftp.Open(sftpOptions)
[/code]




Any help would be greatly appreciated.

Thanks
ErrorMessage.JPG (26.79 KB)

Description: (none)

ErrorMessage.JPG

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
As the error message suggested, you need to set SessionOptions.HostKey. Or actually, you need to upgrade and set SessionOptions.SshHostKeyFingerprint:
http://winscp.net/eng/docs/library_sessionoptions

See also:
https://winscp.net/eng/docs/faq_hostkey
_________________
Martin Prikryl
Bozo
[View user's profile]

Joined: 2014-05-03
Posts: 3
Location: Nowhere
Thank you for the response, but I cannot seem to find the property Hostkey within Sessionoptions. Sad
I am really trying to not have to use SshHostKeyFingerprint as this application will be used by multiple businesses and it would be much easier to handle the key by filename instead of Fingerprint. I have included a jpg showing where I am looking for the Hostkey property.

Thank you
Hostkey.JPG (32.04 KB)

Description: (none)

Hostkey.JPG

Bozo
[View user's profile]

Joined: 2014-05-03
Posts: 3
Location: Nowhere
I was finally able to resolve my issues.

Thank you very much, this is a great product.

[code]
With (sftpOptions)
.Protocol = Protocol.Sftp
.HostName = "xxxxxxxxx.com"
.UserName = "yyyyy"
'.Password = ""
.SshPrivateKeyPath = "C:\FTPFolder\Code\zzzzzzz.ppk"
.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
.PortNumber = 22
End With
[/code]
Ghostwolf
[View user's profile]

Joined: 2014-06-13
Posts: 2
Location: Jeffersonville, IN
Please, how did you finally resolve your issues?

I'm having the same problem trying to connect to a server requiring both password and private key authentication.

My SessionOptions are:
Code:
  .Protocol = Protocol.Sftp
  .PortNumber = 22
  .HostName = [HostName]
  .UserName = [UserName]
  .Password = [Password]
  .SshPrivateKeyPath = [PathToKeyFile]
  .SshHostKeyFingerprint = "ssh-rsa 1023 xx:..."

Although I've specified a location for a logfile, one isn't being created.

I can connect to the server using WinSCP's GUI interface, but my program process fails at Session.Open with a "Disconnected: No supported authentication methods available (server sent: publickey)" error message.

I'd sure appreciate some guidance on this.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Ghostwolf wrote:
Although I've specified a location for a logfile, one isn't being created.

How did you specify a log file?

Quote:
I can connect to the server using WinSCP's GUI interface, but my program process fails at Session.Open with a "Disconnected: No supported authentication methods available (server sent: publickey)" error message.

The "server sent: publickey" means your server support private key authentication only, no password authentication. Are you sure you are using password authentication? Maybe you confuse it for a private key passphrase. See http://winscp.net/eng/docs/faq_passphrase
If that does not help, can you at least attach a log file from GUI?
_________________
Martin Prikryl
Ghostwolf
[View user's profile]

Joined: 2014-06-13
Posts: 2
Location: Jeffersonville, IN
GUI session log file is attached. Naturally, I've replaced anything I could readily identify as sensitive with [xxx].

The server requires both private key and password for authentication.

I've tried specifying the Session.XmlLogPath two ways:
- full Path\Name: the Session.Open results in the above-mentioned error, but no log file;
- Path only: results in "timeout waiting for WinSCP to respond" error.
WinSCP_GUI.log (6.43 KB) [Download]

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Quote:
I've tried specifying the Session.XmlLogPath two ways:
- full Path\Name: the Session.Open results in the above-mentioned error, but no log file;
- Path only: results in "timeout waiting for WinSCP to respond" error.

I need a session log, use Session.SessionLogPath.
_________________
Martin Prikryl
doujiangyoutiao
[View user's profile]

Joined: 2014-06-24
Posts: 2
Location: SHA
Below is the log



. 2014-06-24 15:22:18.562 Host key fingerprint is:
. 2014-06-24 15:22:18.562 ssh-rsa 2048 97:c9:38:5e:21:6b:cf:cc:0a:d0:74:8f:bb:93:3b:f7
. 2014-06-24 15:22:18.562 Initialised AES-256 SDCTR client->server encryption
. 2014-06-24 15:22:18.562 Initialised HMAC-SHA1 client->server MAC algorithm
. 2014-06-24 15:22:18.562 Initialised AES-256 SDCTR server->client encryption
. 2014-06-24 15:22:18.562 Initialised HMAC-SHA1 server->client MAC algorithm
. 2014-06-24 15:22:19.177 Reading private key file "C:\Users\dll\Desktop\lenton.ppk"
! 2014-06-24 15:22:19.177 Using username "lenton".
. 2014-06-24 15:22:19.460 Offered public key
. 2014-06-24 15:22:19.790 Offer of public key accepted
! 2014-06-24 15:22:19.790 Authenticating with public key "imported-openssh-key"
. 2014-06-24 15:22:19.790 Prompt (3, SSH key passphrase, , Passphrase for key "imported-openssh-key": )
. 2014-06-24 15:22:19.791 Disconnected: Unable to authenticate

Below is the code
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "xxxxx",
UserName = "xxxx",
SshPrivateKeyPath = @"C:\Users\dll\Desktop\lenton.ppk",
SshHostKeyFingerprint = "ssh-rsa 2048 xxxx"
//Password = "UjBsA68E"
};

using (Session session = new Session())
{
// Connect
session.SessionLogPath = @"C:\Users\dll\Desktop\sftpLog.txt";
session.Open(sessionOptions);

// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;

TransferOperationResult transferResult;
transferResult = session.PutFiles(@"d:\toupload\*", "/home/user/", false, transferOptions);

// Throw on any error
transferResult.Check();

// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}
}
doujiangyoutiao
[View user's profile]

Joined: 2014-06-24
Posts: 2
Location: SHA
now share to the others who got this problem.
there are two things to do
1.run the pageant.exe with the ppk file and password.
2.run the winSCP with administrator permission.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
doujiangyoutiao wrote:
now share to the others who got this problem.
there are two things to do
1.run the pageant.exe with the ppk file and password.
2.run the winSCP with administrator permission.

Or read the FAQ I referred to earlier:
http://winscp.net/eng/docs/faq_passphrase
The next version (beta to be released in few weeks) will support providing passphrase:
http://winscp.net/tracker/show_bug.cgi?id=816
dibyendur
[View user's profile]

Joined: 2014-07-05
Posts: 1
Location: Philadelphia, USA
I see that a solution has been devised to automate the functionality of authentication using SSH keys having passphrase.

I'm using below format command line in Windows batch (*.bat) scripts:
"C:\Program Files\winscp432\WinSCP.com" <.. Profile name saved in WinSCP client ..> /console /passive /script=<.. FTP Script path & name ..>

The Profile mentioned in the command above has the .ppk SSH key saved, & prompts for the key passphrase. How can I automatically pass the SSH key's passphrase when I'm executing my batch (*.bat) scripts?

Any assistance would be very helpful. Thanks in advance.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
dibyendur wrote:
How can I automatically pass the SSH key's passphrase when I'm executing my batch (*.bat) scripts?

You cannot. Only the future version will allow this.
Meanwhile see http://winscp.net/eng/docs/faq_passphrase
_________________
Martin Prikryl
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