Using multiple variable in command-lin
I have a SFTP site with multiple folders that I need to download all of the *.pdf files into multiple folders on our network. All of local folders and remote folders listed in a text file which I read using the "for /F (tokens=*)" format in a batch file.
for /F "tokens=1, 2 delims=;" %%A in (STD-Folders.txt) do "C:\Program Files (x86)\WinSCP\WinSCP.com" /log="C:\WinSCP\SFTP\Logs\Log.txt" /ini=nul /command "open sftp://my-sftp-site:v!so9tpjszd9O9@sftp.us2.pool.com/ -hostkey=""ssh-rsa 2048 zeKC3/C87n3L12jSehP7r9B1LKHs3Vqo/PguPtVnUxQ=""" "cd /"%%B "lcd E:\Faxes\"%%A "get -delete *.pdf" "lcd E:\Faxes\Z-IDXFiles" "get -delete *.idx" "exit"
This works well but this method opens a session and exits on every iteration. Having 70 folders to download takes a lot of time. I would like to establish one session and then use "cd /remotefolder1" "lcd/ localfolder1" "get -delete *.pdf"
"cd /remotefolder2" "lcd/ localfolder2" "get -delete *.pdf"
"cd /remotefolder3" "lcd/ localfolder3" "get -delete *.pdf"
etc...where the remotefolder1 and localfolder1 are variables from a text file. I do not want to have 70 "cd/" "lcd/ " and "get -delete" statements. Just one that will loop and replace the variable and execute ... replace and execute until the end of the file is reached. Something similar to:
"C:\Program Files (x86)\WinSCP\WinSCP.com" /log="C:\WinSCP\SFTP\Logs\Log.txt" /ini=nul /command "open sftp://my-sftp-site:v!so9tpjszd9O9@sftp.us2.pool.com/ -hostkey=""ssh-rsa 2048 zeKC3/C87n3L12jSehP7r9B1LKHs3Vqo/PguPtVnUxQ="
Start Loop:
"cd /"%%remotefolder "lcd E:\Faxes\"%%localfolder "get -delete *.pdf"
"cd /"%%remotefolder "lcd E:\Faxes\"%%localfolder "get -delete *.pdf"
"cd /"%%remotefolder "lcd E:\Faxes\"%%localfolder "get -delete *.pdf"
End Loop:
Until the end-of-file then "exit".
for /F "tokens=1, 2 delims=;" %%A in (STD-Folders.txt) do "C:\Program Files (x86)\WinSCP\WinSCP.com" /log="C:\WinSCP\SFTP\Logs\Log.txt" /ini=nul /command "open sftp://my-sftp-site:v!so9tpjszd9O9@sftp.us2.pool.com/ -hostkey=""ssh-rsa 2048 zeKC3/C87n3L12jSehP7r9B1LKHs3Vqo/PguPtVnUxQ=""" "cd /"%%B "lcd E:\Faxes\"%%A "get -delete *.pdf" "lcd E:\Faxes\Z-IDXFiles" "get -delete *.idx" "exit"
This works well but this method opens a session and exits on every iteration. Having 70 folders to download takes a lot of time. I would like to establish one session and then use "cd /remotefolder1" "lcd/ localfolder1" "get -delete *.pdf"
"cd /remotefolder2" "lcd/ localfolder2" "get -delete *.pdf"
"cd /remotefolder3" "lcd/ localfolder3" "get -delete *.pdf"
etc...where the remotefolder1 and localfolder1 are variables from a text file. I do not want to have 70 "cd/" "lcd/ " and "get -delete" statements. Just one that will loop and replace the variable and execute ... replace and execute until the end of the file is reached. Something similar to:
"C:\Program Files (x86)\WinSCP\WinSCP.com" /log="C:\WinSCP\SFTP\Logs\Log.txt" /ini=nul /command "open sftp://my-sftp-site:v!so9tpjszd9O9@sftp.us2.pool.com/ -hostkey=""ssh-rsa 2048 zeKC3/C87n3L12jSehP7r9B1LKHs3Vqo/PguPtVnUxQ="
Start Loop:
"cd /"%%remotefolder "lcd E:\Faxes\"%%localfolder "get -delete *.pdf"
"cd /"%%remotefolder "lcd E:\Faxes\"%%localfolder "get -delete *.pdf"
"cd /"%%remotefolder "lcd E:\Faxes\"%%localfolder "get -delete *.pdf"
End Loop:
Until the end-of-file then "exit".