Post a reply

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)


Topic review



This thread can be closed. It seems like our third part is already copying the file to the folder in their script, hence the file can't be moved to the folder. My bad, sorry.


Thanks for your reply!

Here's a log file with a successful move.

With the servers log file you mean the FTP server I'm connecting to? It's a third part, but I'll see if I can get some information from them.

Re: File isn't moved correctly

There's nothing wrong with your code.
You should inspect the server's log file to see why it fails the move.

Can you attach a log file from a successful session?

File isn't moved correctly


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.

#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

$session.SessionLogPath = $sessionLogPath
# Connect to FTP server

# Copy files
$session.GetFiles($RemoteFiles, $LocalFolderAgresso).Check()
$session.GetFiles($RemoteFiles, $LocalFolderFastnet).Check()

# Move files
$session.MoveFile($RemoteFiles, $RemoteOldFolder)
#Disconnect session

exit 0
catch [Exception]
Write-Host $_.Exception.Message
exit 1

I've attached the log file.