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

Advertisement

jimbo311
Joined:
Posts:
4
Location:
USA

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!

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,469
Location:
Prague, Czechia

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

Reply with quote

jimbo311
Joined:
Posts:
4
Location:
USA

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!!

Reply with quote

Advertisement

You can post new topics in this forum