Topic "Synchronization Aborted on Error - How to use "Option Batch Abort"?"

Author Message
jpang
[View user's profile]

Joined: 2015-06-28
Posts: 2
Location: Toronto
I adopted this script from the forum for use with directory synchronization of my FTP site. It works well except that the script will quit if one of the files fails to download. It appeared to be prompting a user input and then retried a few times. Afterward, it disconnected instead of moving on to the next file.

What I expect the script to do is to continue the synchronization by skipping to the next file in a situation like this. I read about "option batch abort" and "option confirm off" but do not know how I can apply it to the script. I am not sure if that would work too. Can anyone please help?

Log entries and the script I used are attached below.


========== Synchronization log ==================================
. 2015-06-28 09:47:43.046 Can't open file 'D:\Clients\ICON'.
. 2015-06-28 09:47:43.046 System Error. Code: 5.
. 2015-06-28 09:47:43.046 Access is denied
. 2015-06-28 09:47:43.046 Copying files from remote side failed.
* 2015-06-28 09:47:43.046 (ExtException) **Can't open file 'D:\Clients\ICON'.
* 2015-06-28 09:47:43.046 System Error. Code: 5.
* 2015-06-28 09:47:43.046 Access is denied**
* 2015-06-28 09:47:43.046 Copying files from remote side failed.
. 2015-06-28 09:47:43.062 Asking user:
. 2015-06-28 09:47:43.062 Error transferring file '/ICON'. ("Can't open file 'D:\Clients\ICON'.
. 2015-06-28 09:47:43.062 System Error. Code: 5.
. 2015-06-28 09:47:43.062 Access is denied","Copying files from remote side failed.")
< 2015-06-28 09:47:43.062 Script: Error transferring file '/ICON?'.
< 2015-06-28 09:47:43.062 Script: Can't open file 'D:\Clients\ICON?'.
< 2015-06-28 09:47:43.062 System Error. Code: 5.
< 2015-06-28 09:47:43.062 Access is denied
< 2015-06-28 09:47:43.062 Copying files from remote side failed.
* 2015-06-28 09:47:43.062 (EScpSkipFile) Error transferring file '/ICON'.
* 2015-06-28 09:47:43.062 Can't open file 'D:\Clients\ICON'.
* 2015-06-28 09:47:43.062 System Error. Code: 5.
* 2015-06-28 09:47:43.062 Access is denied
* 2015-06-28 09:47:43.062 Copying files from remote side failed.
. 2015-06-28 09:47:43.077 Script: Failed
> 2015-06-28 09:47:43.343 Script: exit
. 2015-06-28 09:47:43.343 Script: Exit code: 1
. 2015-06-28 09:47:43.343 Disconnected from server
==============================================================================


# ============ Synchronization Script ==========================================

param (
$localPath = "C:\upload\*",
$remotePath = "/home/user/",
$backupPath = "C:\backup\"
)

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 = "example.com"
$sessionOptions.UserName = "user"
$sessionOptions.Password = "mypassword"
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"

$session = New-Object WinSCP.Session

try
{
# Connect
$session.Open($sessionOptions)

# Upload files, collect results
$transferResult = $session.PutFiles($localPath, $remotePath)

# Iterate over every transfer
foreach ($transfer in $transferResult.Transfers)
{
# Success or error?
if ($transfer.Error -eq $Null)
{
Write-Host ("Upload of {0} succeeded, moving to backup" -f
$transfer.FileName)
# Upload succeeded, move source file to backup
Move-Item $transfer.FileName $backupPath
}
else
{
Write-Host ("Upload of {0} failed: {1}" -f
$transfer.FileName, $transfer.Error.Message)
}
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}

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

===============================================================================
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
WinSCP .NET assembly does not support an option to continue on errors yet.
jpang
[View user's profile]

Joined: 2015-06-28
Posts: 2
Location: Toronto
Thanks. I will find a workaround.


prikryl wrote:
WinSCP .NET assembly does not support an option to continue on errors yet.
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