Post a reply

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

martin

Re: Prepend timestamp for wildcard upload deleting characters from filename

WinSCP operation masks do not support prepending (imo, it's actually how the masks work in general with all Windows/Linux command-line tools, so it should not be really surprising).

You would have to use more powerful scripting language. Like PowerShell with use of WinSCP .NET assembly.
https://winscp.net/eng/docs/library_powershell

Something like this (untested):
$remotePath = "/remote/path"
$timestamp = (Get-Date -Format "yyyyMMdd")
$dirInfo = $session.ListDirectory($remotePath)
foreach ($file in $dirInfo.Files)
{
    $newName = $timestamp + "_" + $file.Name
    $newPath = [WinSCP.RemotePath]::Combine($remotePath, $newName)
    $session.MoveFile($file.FullName, $newName)
}
onetwotreee

Prepend timestamp for wildcard upload deleting characters from filename

Hello all,

I'm uploading all files in a directory to a remote SFTP site and if I prepend a timestamp the timestamp will remove characters from the filename e.g.

The command I'm using:
put *.* %TIMESTAMP#yyyymmdd%*.*

What I'm expecting:
20220914_abc_defghij_klmn.csv

The result:
20220914_ij_klmn.csv

How can I fix this?