Topic "Unable to use dateTime stamp in log file name"

Author Message
ashish.atwal
[View user's profile]

Joined: 2017-10-31
Posts: 2
Location: Noida
Hi Team,

I have made SFTP connection in file named "File_Put.txt" which is working fine

I have made a bat file named "Transfer.bat" in which I am scanning each folder of source for .txt file and transfer the files to the destination folder (source and destination folder names are exactly same)
My Transfer.bat contains the following code :
FOR /R "C:\source\" %%G IN (*.txt) DO (
FOR /F %%i in ("%%G") do (
set dest_path=%%~pi
set dest_path=!dest_path:\=,!

FOR %%i in (!dest_path!) do (
echo %%i
set dest_folder=%%i

)
)
"C:\Program Files (x86)\WinSCP\winscp.exe" /ini=nul /log='C:\WinSCPScript\DateWiseTest\File_Put_!M!D!Y.log' /script=C:\WinSCPScript\DateWiseTest\File_Put.txt /parameter // %%G /!dest_folder!/
)

exit /b 0


so in the above script scan all folders under "source" folder and it is sending two parameters to "File_Put.txt"
1. %%G :- the current txt file name.
2. dest_folder :- folder name contains the txt file (source and destination folder are same for each file)

and my "File_Put.txt" is just making the SFTP connection to server and sending the file to destination folder as shown below :

open sftp://"*****":"****"*****
option transfer binary
put -nopermissions -nopreservetime %1% %2%
close
exit


where %1% and %2% are the parameters passed from "Transfer.bat".
connection details are hidden but are working fine at my end.

Now the problem is that if you observe the below line in the "Transfer.bat" :

"C:\Program Files (x86)\WinSCP\winscp.exe" /ini=nul /log='C:\WinSCPScript\DateWiseTest\File_Put_!M!D!Y.log' /script=C:\WinSCPScript\DateWiseTest\File_Put.txt /parameter // %%G /!dest_folder!/

in the bold area if I name my log file as "File_Put.log" then it runs fine but when I want to apply DateTime stamps to it as already done like "File_Put_!M!D!Y.log" then it is not running it throws error as attached.

I am very sure that it is taking wrong parameters to File_Put.txt which throws exception.

Please help me to resolve this issue as my target is to generate session log file date wise daily.

Regards,
Ashish Singh Atwal
winSCPerror.jpg (17.49 KB)

Description: (none)

winSCPerror.jpg

Advertisements
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27059
Location: Prague, Czechia
I assume you have a delayed expansion enabled in your batch file (although your code snippet does not show that).
With delayed expansion, you have to escape the ! with ^.
Also, you have to use double quotes.
/log="C:\WinSCPScript\DateWiseTest\File_Put_^!M^!D^!Y.log"
ashish.atwal
[View user's profile]

Joined: 2017-10-31
Posts: 2
Location: Noida
martin wrote:
I assume you have a delayed expansion enabled in your batch file (although your code snippet does not show that).
With delayed expansion, you have to escape the ! with ^.
Also, you have to use double quotes.
/log="C:\WinSCPScript\DateWiseTest\File_Put_^!M^!D^!Y.log"


Thanx buddy it solved my problem Smile. Could you please elaborate "delayed expansion"?
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27059
Location: Prague, Czechia
Quote:
Could you please elaborate "delayed expansion"?

That has nothing to do with WinSCP.
The first hit in google:
https://ss64.com/nt/delayedexpansion.html
Advertisements

You can post new topics in this forum

Search

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License