I am explaning my code again so that you get some idea :
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 (
FOR %%i in (!dest_path!) do (
"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 :
option transfer binary
put -nopermissions -nopreservetime %1% %2%
where %1% and %2% are the parameters passed from "Transfer.bat".
connection details are hidden but are working fine at my end.
Your help is needed in the following queries :
- As 'Transfer.bat' is scanning each folder and uses 'File_Put.txt' to SFTP file to the server if any found, my question is how do I confirm back in my 'Transfer.bat' that my file is transferred so that I can move that file to a backup folder.
- As for now for each file 'File_Put.txt' will be called which will open and close the connection every time. Can we have some better approach in which firstly it'll open the connection then scan the whole folders recursively, transfers the file and in the end closes the connection?
Hope I am able to make you understand what I wanted to do. Could you please help me in this? Thanx in advance :)