Thanks Martin! That worked and everything else is going through with my script.
You're a freaking rockstar! I'll donate to you when I get home.
You're a freaking rockstar! I'll donate to you when I get home.
SessionOptions.PrivateKeyPassphrase:
Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed. Server sent command exit status 0.
Authentication log (see session log for details):
Using username "PlutoP".
Authenticating with public key "rsa-key-20190501".
Authentication failed."
At C:\Users\PlutoP\Documents\powershellscript.ps1:20 char:5
+ $session.Open($sessionOptions)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SessionRemoteException
Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed. Server sent command exit status 0.
Authentication log (see session log for details):
Using username "PlutoP".
Server refused our key.
Authentication failed."
At C:\Users\PlutoP\Documents\Doc.ps1:20 char:5
+ $session.Open($sessionOptions)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SessionRemoteException
I'd rather use Public/Private Keys but I need help with replacing the username/password code with some string:SshPrivateKeyPathand using the.puband.ppkfiles to authenticate.
SessionOptions.SshPrivateKeyPath to the path of your .ppk file.
# Load WinSCP .NET assembly
Add-Type -Path "C:\Users\PlutoP\Downloads\NewFolder\WinSCPnet.dll"
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "SFTP server address"
UserName = "PlutoP"
Password = "xxxxxxxxxx"
SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
}
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)