File isn't moved correctly

Advertisement

rasmus.hvitfeldt
Joined:
Posts:
4

File isn't moved correctly

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.
  • 2016-04-11_05-30-04.log (14.4 KB, Private file)

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

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?

Reply with quote

Guest

Hi,

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.
  • 2016-04-04_10-00-05.log (13.84 KB, Private file)

Reply with quote

Advertisement

You can post new topics in this forum