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


tiwas wrote:

But...WinSCP won't download files or folders with '{' or '}' in the name.

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Thanks! Wasn't even aware of that class :)

But...WinSCP won't download files or folders with '{' or '}' in the name.

As you can see from the log, the transfer succeeds. The problem starts with this
$latestTransfer = $transferResult.Transfers | Sort-Object -Property @{ Expression = { (Get-Item $_.Destination).LastWriteTime } } `
-Descending | Select-Object -First 1

More specifically, the failure first happens here: Get-Item $_.Destination when there are '[' or ']' in the file name.

[DBG]: PS D:\WinSCP-5.17.2-Automation>> Get-Item $_.Destination
Get-Item : Cannot bind argument to parameter 'Path' because it is null.
At line:1 char:10
+ Get-Item $_.Destination
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-Item], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetItemCommand

I'm new to powershell, but I'm pretty sure this is the culprit.

My solution, which in my book is just a band-aid is the following renaming of all files - but at least it doesn't crash:
Get-ChildItem $destPath -recurse | Rename-Item -NewName { $_.Name -replace '\[.*\]', '' }
$lastTimestamp = (Get-Item ($latestTransfer.Destination.ToString() -replace ('\[.*\]', ""))).LastWriteTime

Re: Question about WinSCP.Session.GetFiles().Transfers

Sorry, I do not understand what your code is doing. So neither I understand your problem. Please give us more information. And more code.

Question about WinSCP.Session.GetFiles().Transfers


I've been playing around with some of the scripts here in order to set up continuous one-way file replication. This works incredibly well, and I'm stoked! Well, almost ;)

Thing is, as long as I only transfer files, there's only joy. If there are folders in the mix things get a little bit more tricky.

In my example, the folder has a newer timestamp than the files contained inside it. Why that is I have no idea, but it doesn't really matter. It's like that. Now, the code snippet (yes, I've removed code for brevity (?) and it's probably important) will test for the newest *file*. It will not take folders into account. And so it will continue to download empty folders.

Is there a way to also look for the folder timestamp?


$session = New-Object WinSCP.Session
$transferResult = $session.GetFiles($sourcePath, $destPath, $False, $transferOptions)
$latestTransfer =
   $transferResult.Transfers |
   Sort-Object -Property @{ Expression = { (Get-Item $_.Destination).LastWriteTime } } `
      -Descending |
   Select-Object -First 1