Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Same problem

BehsunSchool wrote:

I have the same problem. What yo do?

Can you give us details about your problem?
BehsunSchool

Same problem

I have the same problem. What yo do?
PHRI_John

Re: session.Open doesn't appear to work - FIXED

On a lark while I was distracted, I thought I would run the "Generate session URL/Code" and I came up with a different SshHostKeyFingerprint.
When I used your generated value, it worked flawlessly!!!


PHRI_John wrote:

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
"SshHostKeyFingerprint = "ssh-ed25519 256 hhpXw3VGfQne8aCELk9CK7e54SFqayv+GqOdU7gu8pg="
}

$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
PHRI_John

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