Transfer folder from one SFTP server to another every day

1.2k views Asked by At

I have two different servers. I use WinSCP to transfer a folder manually:

  • I connect to SFTP on SVR-01 -> Transfer folder to my local machine

  • I connect to SFTP on SVR-02 -> Transfer folder from my local machine to SVR-02

What I want?:

I would like to do it automatically.

Example: in a command OR script, the SVR-01 transfer folder /opt/home/files-everyday/ to SVR-02 /opt/backup/

When transfer is finished, delete /opt/home/files-everyday/ from SVR-01.

This should be done every day.

One folder is created every day by date "20150613" in SVR-01 and this folder to be automatically transferred to the SVR-02.

1

There are 1 answers

0
Martin Prikryl On BEST ANSWER

You can use WinSCP scripting from a Windows batch file:

@echo off

mkdir %temp%\intermediate

winscp.com /log=c:\path\log.log /command ^
    "open sftp://user1:[email protected]/ -hostkey=""ssh-rsa 2048 87:d6...a7""" ^
    "get /opt/home/files-everyday/* %temp%\intermediate\" ^
    "open ftps://user2:[email protected]/" ^
    "put %temp%\intermediate\* /opt/backup/" ^
    "session 1" ^
    "rm /opt/home/files-everyday/*" ^
    "exit"

rmdir /q /s %temp%\intermediate

Then use the Windows scheduler to run the script regularly (every day).