Topic "File isn't moved correctly"

Author Message
rasmus.hvitfeldt
[View user's profile]

Joined: 2015-11-06
Posts: 4
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

Description: (none)

Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24991
Location: Prague, Czechia
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?
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

Description: (none)

rasmus.hvitfeldt
[View user's profile]

Joined: 2015-11-06
Posts: 4
Hi,

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.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License