How do I create a unique filename when -put- for each file picked up.

Advertisement

cougarmutt
Guest

How do I create a unique filename when -put- for each file picked up.

The below script overwrite if it picks up multiple files
I need for it to create a unique filename for each file picked up.
the %RANDOM% does not work


option echo off
option batch on
option confirm off
open sftp://<USERNAME>:<PASSWORD>@<SFTP SERVER URL>

#GRAB SYSCO FILES AND MOVE TO THE EDI\SYSCO\ FOLDER ON BLACKSMITH
lcd "C:\Users\ccancilla\Documents\WinSCP\Blacksmith\SYSCO"
cd /EDI/SYSCO/
put -nopermissions -nopreservetime "SYSCO*.txt" SYSCO_867_%TIMESTAMP%.txt

#GRAB USFS FILES AND MOVE TO THE EDI\USFS\ FOLDER ON BLACKSMITH
lcd "C:\Users\ccancilla\Documents\WinSCP\Blacksmith\USFS\"
cd /EDI/USFS/
put -delete -append -nopermissions -preservetime "USFS*.txt" USFS_867_%TIMESTAMP%.txt

exit

Reply with quote

Advertisement

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

Re: How do I create a unique filename when -put- for each file picked up.

WinSCP does not have a function to generate random file names.

But it's easy to write a PowerShell script with use of WinSCP .NET assembly and its Session.EnumerateRemoteFiles and Session.PutFiles methods and Get-Random PowerShell cmdlet.

https://winscp.net/eng/docs/library_powershell
https://winscp.net/eng/docs/library_session_enumerateremotefiles
https://winscp.net/eng/docs/library_session_putfiles

Reply with quote

Advertisement

You can post new topics in this forum