Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

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


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
#This gives the error and keeps going
$session.add_QueryReceived( {
LogWrite $($_.Message)
} )

$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FileMask = "| ~*"

$synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote, "\\Development\Forms\","/Forms/",$False,$False,[WinSCP.SynchronizationCriteria]::Time,$transferOptions)

options is 7th argument of SynchronizeDirectories, not 5th.

$session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote,"C:\Users\1234\desktop\testupload\", "/BatchAPI/test/", $False, $False, [SynchronizationMode.SynchronizationCriteria]::Time, $transferOptions)

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

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

Your second snippet is just wrong.

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?


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


$synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote, "C:\Users\1234\desktop\testupload\", "/BatchAPI/test/", $False, "|~*")

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

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
and or skip hidden files as this is temp file "~$Automated.xlsx"

$synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote, "\\\data","/data/", $False)


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 '\\\data\Cases\~$Automated.xlsx'.
System Error. Code: 32.
The process cannot access the file because it is being used by another process"