Continue on error while using PowerShell script? "System Error. Code: 32"

Advertisement

acem77
Joined:
Posts:
20
Location:
usa

Continue on error while using PowerShell script? "System Error. Code: 32"

Hello,
How can I keep the job running when a file is open while using PowerShell?
would making the change here resolve my issue?
Synchronize Options
https://winscp.net/eng/docs/ui_keepuptodate
and or skip hidden files as this is temp file ~$Automated.xlsx

Example,
$synchronizationResult =
    $session.SynchronizeDirectories(
        [WinSCP.SynchronizationMode]::Remote, "\\toys.com\data","/data/",
        $False)
Thanks
System Error. Code: 32.
The process cannot access the file because it is being used by another process
Permissions of kept with their defaults
Timestamp of kept with its default (current time)
Error: Exception calling "Check" with "0" argument(s): "Can't open file '\\toys.com\data\Cases\~$Automated.xlsx'.
System Error. Code: 32.
The process cannot access the file because it is being used by another process

Reply with quote

Advertisement

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

Re: Continue on error while using powershell script? "System Error. Code: 32"

You can exclude files starting with ~ using a filemask | ~*.
https://winscp.net/eng/docs/file_mask

Or you can use Session.QueryReceived to continue on error:
https://winscp.net/eng/docs/library_session_queryreceived
https://winscp.net/eng/docs/library_example_recursive_download_custom_error_handling

The next version of WinSCP (5.14) will allow excluding hidden files.

Reply with quote

acem77
Joined:
Posts:
20
Location:
usa

Thanks for the reply,
so far I have had no luck and tried the below methods. Do you have a full example? could I have access to the beta?

Thanks
# Synchronize files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FileMask = "~*"
$synchronizationResult =
    $session.SynchronizeDirectories(
        [WinSCP.SynchronizationMode]::Remote,
        "C:\Users\1234\desktop\testupload\", "/BatchAPI/test/", $False,
        $transferOptions)
And
$synchronizationResult =
    $session.SynchronizeDirectories(
        [WinSCP.SynchronizationMode]::Remote,
        "C:\Users\1234\desktop\testupload\", "/BatchAPI/test/", $False,
        "|~*")

Reply with quote

martin
Site Admin
martin avatar

Your first snippet is almost correct, except that I've suggested | ~*, not ~*

Your second snippet is just wrong.

Reply with quote

acem77
Joined:
Posts:
20
Location:
usa

I have updated and tried this earlier,
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FileMask = "| ~*"
    
$synchronizationResult = 
    $session.SynchronizeDirectories(
        [WinSCP.SynchronizationMode]::Remote,
        "C:\Users\1234\desktop\testupload\", "/BatchAPI/test/", $False,
        $transferOptions)
does the mask work with Synchronization

I see this is set, but I still get the same errors in the log locked files with ~ in the name.
WinSCP.SessionRemoteException: Can't open file 'C:\Users\1234\desktop\testupload\~$New...
PS C:\Users\1234> $transferOptions

PreserveTimestamp : True
FilePermissions   : 
TransferMode      : Binary
FileMask          : | ~*
ResumeSupport     : default
SpeedLimit        : 0
OverwriteMode     : Overwrite

Reply with quote

Advertisement

acem77
Joined:
Posts:
20
Location:
usa

Thanks for the example this works for me. With my limited understanding I am not sure how I am to know the argument order for options.
$session = New-Object WinSCP.Session
# Will continuously report progress of synchronization
$session.add_FileTransferred( { FileTransferred($_) } )
# Connect
$session.Open($sessionOptions)
#This gives the error and keeps going
$session.add_QueryReceived( { 
    LogWrite $($_.Message)
    $_.Continue()
} )
 
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FileMask = "| ~*"
 
$synchronizationResult =
    $session.SynchronizeDirectories(
        [WinSCP.SynchronizationMode]::Remote,
        "\\Development\Forms\", "/Forms/", $False,
        $False, [WinSCP.SynchronizationCriteria]::Time, $transferOptions)

Reply with quote

Advertisement

You can post new topics in this forum