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:SshPrivateKeyPath
and using the.pub
and.ppk
files 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)
# Transfer files
$session.PutFiles("C:\Users\PlutoP\Download\Document.csv", "/PlutoP/NewFolder/*").Check()
}
finally
{
$session.Dispose()
}
SshPrivateKeyPath
and using the .pub
and .ppk
files to authenticate.
cmdlet Move-WinSCPItem at command pipeline position 1
Supply values for the following parameters:
WinSCPSession:
WinSCPSession
value. It just says...
Move-WinSCPItem : Cannot process argument transformation on parameter 'WinSCPSession'. Cannot convert the "" value of type "System.String" to type "WinSCP.Session".
At line:3 char:1
+ Move-WinSCPItem -Path "/PlutoP/NewFolder/Document.csv" -Destination "C:\U ...
Send-WindSCPItem
, Move-WinSCPSessionOption
, Receive-WinSCPItem
, New-WinSCPSession
, New-WinSCPSessionOption
. Needless to say, I am new to this and would be grateful for any assistance!
# Piping the WinSCPSession into the Receive-WinSCPItem auto disposes the WinSCP.Session object after completion.
New-WinSCPSessionOption -Hostname "SFTP server address" -Credential (Get-Credential) -SshHostKeyFingerprint "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
Move-WinSCPItem -Path "/PlutoP/NewFolder/Document.csv" -Destination "C:\Users\PlutoP\Download\Document.csv"