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 https://winscp.net/eng/docs/faq_passphrase
How can I automatically pass the SSH key's passphrase when I'm executing my batch (*.bat) scripts?
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.
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.
Session.SessionLogPath
.
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.
.Protocol = Protocol.Sftp
.PortNumber = 22
.HostName = [HostName]
.UserName = [UserName]
.Password = [Password]
.SshPrivateKeyPath = [PathToKeyFile]
.SshHostKeyFingerprint = "ssh-rsa 1023 xx:..."
SessionOptions.HostKey
. Or actually, you need to upgrade and set SessionOptions.SshHostKeyFingerprint
:
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