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.

Options
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)

Options

Topic review

jimbo311

@martin Thank you, this points me in the right direction!
jimbo311

Re: Session.PutFiles failed to transfer a file, how can I make WinSCP go back and try to recopy it

Thank you for the reply, I am pretty new to all of this, so, is there a way with in a PowerShell script to catch the error, and then if there is an error to then do the Session.SynchronizeDirectories?

I guess that is really what I am looking for, a way to catch the error and if there is an error to go sync the directories.

Thanks again!!
martin

Re: Session.PutFiles failed to transfer a file, how can I make WinSCP go back and try to recopy it

I'm not sure what are you looking for exactly. Just call Session.PutFiles for that specific file.

Alternatively, you might want to try synchronization to copy only the files that need to be updated/differ, for whatever reason. See Session.SynchronizeDirectories:
https://winscp.net/eng/docs/library_session_synchronizedirectories
jimbo311

Session.PutFiles failed to transfer a file, how can I make WinSCP go back and try to recopy it

Hi all,

I am transferring a lot of files via WinSCP and randomly one will fail, it happens, no big deal, but is there a way I can have WinSCP go back to that file and try to copy it again?

The error I am getting is
The process cannot access the file because it is being used by another process

This occurs during an update process to where several apps are being updated one by one in order, and it happens in the middle of the process.

Here is the majority of the code, should be enough to see what is going on the path for $updateFolder is correct as there are say 1000 files in that path, and the random one will be missed from time to time (it is not often at all, but I am try to deal with the error handling).
Add-Type -Path "path to WinSCPnet.dll"
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.ParseUrl("ftp://${username}:$password@$url")
$session = New-Object WinSCP.Session
$session.Open($sessionOptions)
$session.PutFiles($updateFolder, "update path").Check()

Any suggestions on how to have it go back and copy the one file it missed?

Thanks all!