WinSCP - scripts to open connection and copy files

Advertisement

jobzjoseph
Joined:
Posts:
1
Location:
Kuwait

WinSCP - scripts to open connection and copy files

We have a small problem that we need a solution for :-

We are trying to copy files from a non SFTP Windows server to an SFTP server using Winscp.
We need to create a batch that can open the session and keep it active for atleast 8 hours and keep copying files on regular basis or sync them.
In order to do that we thought the best approach would be to create a batch to login to SFTP server and keep the server active and at the same time create another batch to keep copying the files on loop.

Appreciate your support and best recommendations with the above logic. We have created some scripts to open the session and copy the files as below.
Login to session
option batch off
option confirm off
open sftp://testuser01:P@ssw0rd@hostname
Copy the Files
option batch off
option confirm off
open sftp://testuser01:P@ssw0rd@hostname/
cd Swifttest/paymentsafe/PS_TO_SAA
put "D:\paymentsafe_bbyn\localFolder\From_PS_To_SAA\*.out"
put "D:\paymentsafe_bbyn\localFolder\From_PS_To_SAA\*.txt"
# Disconnect
close
exit

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
33,710
Location:
Prague, Czechia

Re: WinSCP - scripts to open connection and copy files

You cannot do loop in WinSCP script.
So either you will have to loop outside of the script (which means a reconnect for each iteration).

Or use WinSCP .NET assembly from your favorite scripting language (like PowerShell), where you can do the loop.
https://winscp.net/eng/docs/library_powershell

Or use keepuptodate command:
https://winscp.net/eng/docs/scriptcommand_keepuptodate

Reply with quote

Advertisement

You can post new topics in this forum