Topic "Problem putting files using SFTP and public / private key in"

Author Message
stevotodd
[View user's profile]

Joined: 2012-10-22
Posts: 1
Location: Somerset, U.K.
Hi there,

I am having trouble getting a PUT command to work using a public/private key combination in script (VB.NET). I have successfully managed to get it to work to the same connection using :-

a) the username / password via script
b) the public / private key via the WinSCP GUI

I assume therefore that it is a code problem. Here is the VB.NET code :-

Try
' Setup session options
Dim sessionOptions As New SessionOptions
With sessionOptions
.Protocol = Protocol.Sftp
.HostName = "xxxxxxxx"
.UserName = "XXXXX"
.SshHostKeyFingerprint = "xxxxxxxxx"
.SshPrivateKeyPath = "xxxxxx"
End With

Using session As Session = New Session

session.ExecutablePath = "xxxxxxx"

' Connect
session.Open(sessionOptions)

' Upload files
Dim transferOptions As New TransferOptions
transferOptions.TransferMode = TransferMode.Binary

Dim transferResult As TransferOperationResult
transferResult = session.PutFiles("xxxxxxx", "/xxxxx/", False, transferOptions)

' Throw on any error
transferResult.Check()

' Print results
Dim transfer As TransferEventArgs
For Each transfer In transferResult.Transfers
lblResult.Text += String.Format("Upload of {0} succeeded", transfer.FileName)
Next
End Using

lblResult.Text += "OK"
lblResult.Text += Now().ToLongTimeString()
Catch exx As Exception
lblResult.Text += Now().ToLongTimeString()
End Try

The error is coming from this line :-

session.Open(sessionOptions)

And the error message is :-

Connection has been unexpectedly closed. Server sent command exit status 0.

I haven't managed to find any code examples (in VB.NET or otherwise), so please could you either point me in the direction of some working code, or let me know why the script isn't working directly.

I'm not sure if this is a factor or not, but the connection does take around 80-90s to complete successfully.

Many thanks,

stevotodd
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
stevotodd wrote:
I am having trouble getting a PUT command to work using a public/private key combination in script (VB.NET). I have successfully managed to get it to work to the same connection using :-

a) the username / password via script
b) the public / private key via the WinSCP GUI

Turn on logging both in GUI (or script) and .NET (Session.SessionLogPath) and compare the logs. Attach the logs here if you do not find the cause.
_________________
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