session.Open doesn't appear to work
I am trying to automate an upload to an SFTP site.
We have configured Private/Public keys.
The transfer works from the console.
When I run the script, the session.Open() command appears to return $null and drops to the "finally" section. The put never occurs.
What have I missed?
If possible, how would I leverage the {synchronize remote "local_dir remote_dir"} command?
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
$sessionOptions = $null
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "secureftp.********.com"
UserName = "p*****"
Password = ""
SshPrivateKeyPath = "C:\CertificatesAndPrivateKeys\P*******.ppk"
SshHostKeyFingerprint = "ssh-rsa 2048 6b:81:10:0b:ac:d5:a1:fd:03:72:8d:01:c9:37:c5:38"
}
$session = $null
$session = New-Object WinSCP.Session
try
{
# Connect
$session_status = $session.Open($sessionOptions)
# Transfer files
$sftp_put_result = $session.PutFiles($expath, "/uploads/*").Check()
}
finally
{
Write-Host $_
$session.Dispose()
}
$session has the following attributes:
ExecutablePath :
ExecutableProcessUserName :
ExecutableProcessPassword :
AdditionalExecutableArguments :
DefaultConfiguration : True
DisableVersionCheck : False
IniFilePath :
ReconnectTime : 00:02:00
ReconnectTimeInMilliseconds : 120000
DebugLogPath :
DebugLogLevel :
SessionLogPath :
XmlLogPath :
XmlLogPreserve : False
HomePath :
Timeout : 00:01:00
Output : {winscp> option batch on, batch on , reconnecttime 120 , winscp> option confirm off...}
Opened :
UnderlyingSystemType : WinSCP.Session
We have configured Private/Public keys.
The transfer works from the console.
When I run the script, the session.Open() command appears to return $null and drops to the "finally" section. The put never occurs.
What have I missed?
If possible, how would I leverage the {synchronize remote "local_dir remote_dir"} command?
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
$sessionOptions = $null
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "secureftp.********.com"
UserName = "p*****"
Password = ""
SshPrivateKeyPath = "C:\CertificatesAndPrivateKeys\P*******.ppk"
SshHostKeyFingerprint = "ssh-rsa 2048 6b:81:10:0b:ac:d5:a1:fd:03:72:8d:01:c9:37:c5:38"
}
$session = $null
$session = New-Object WinSCP.Session
try
{
# Connect
$session_status = $session.Open($sessionOptions)
# Transfer files
$sftp_put_result = $session.PutFiles($expath, "/uploads/*").Check()
}
finally
{
Write-Host $_
$session.Dispose()
}
$session has the following attributes:
ExecutablePath :
ExecutableProcessUserName :
ExecutableProcessPassword :
AdditionalExecutableArguments :
DefaultConfiguration : True
DisableVersionCheck : False
IniFilePath :
ReconnectTime : 00:02:00
ReconnectTimeInMilliseconds : 120000
DebugLogPath :
DebugLogLevel :
SessionLogPath :
XmlLogPath :
XmlLogPreserve : False
HomePath :
Timeout : 00:01:00
Output : {winscp> option batch on, batch on , reconnecttime 120 , winscp> option confirm off...}
Opened :
UnderlyingSystemType : WinSCP.Session