Hello, I am receiving this error when trying to upload a file to a particular remote folder. I am not sure why I am getting this error. I use this same script with other companies and it works fine. If I use the GUI WinSCP interface, I have no issue. I do see the file on the other end and it is both encrypted and unencrypted.
ERROR:
"Exception calling "Check" with "0" argument(s): "Cannot create remote file '/Folder/file.pgp'.
No Such file or directory.
Error code: 2
Error message from server (en): "
At line:1 char:2
+ $Session.PutFiles("D:\tasks\file\*.*", "/Folder/", $False, $transferOptions).Check().
A copy of my script:
Start-Transcript -Path "D:\tasks\upload_log.txt"
# Load WinSCP .NET assembly
Add-Type -Path "D:\tasks\WinSCPnet.dll"
# Setup SFTP session to company
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::sftp
HostName = "Sftp.company.com"
PortNumber = 22
UserName = "userid"
SshHostKeyFingerprint = "ssh-rsa 2048 b/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
SshPrivateKeyPath = "d:\tasks\key pair.ppk"
PrivateKeyPassphrase = "password"
}
$session = New-Object WinSCP.Session
try
{
# Connect to company
$session.Open($sessionOptions)
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off
$transferOptions.PreserveTimestamp = $false
# Uploads file
write-host "Uploading File"
$Session.PutFiles("D:\tasks\file\*.*", "/Folder/", $False, $transferOptions).Check()
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
Stop-Transcript