Hey,
I got a script that is supposed to move a file on the FTP server and also copy it to a local folder. The copy works, but moving the file only creates it in the remote folder on the FTP and leaves the file in the original place. This only happens with the script is ran by a scheduled task on Windows Server 2012 R2. When I run the script manually it works like it's supposed to. The exit code for the script is 0x1.
try
{
#Load WinSCP .NET assembly
Add-Type -Path 'WinSCPnet.dll'
#Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = $Server
$sessionOptions.UserName = $Username
$sessionOptions.SecurePassword = ConvertTo-SecureString $EncryptedPW
$sessionOptions.SshHostKeyFingerprint = $SSHKey
$session = New-Object WinSCP.Session
try
{
$session.SessionLogPath = $sessionLogPath
# Connect to FTP server
$session.Open($sessionOptions)
# Copy files
$session.GetFiles($RemoteFiles, $LocalFolderAgresso).Check()
$session.GetFiles($RemoteFiles, $LocalFolderFastnet).Check()
# Move files
$session.MoveFile($RemoteFiles, $RemoteOldFolder)
}
finally
{
#Disconnect session
$session.Dispose()
}
exit 0
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}
I've attached the log file.