Last active
November 15, 2020 02:49
-
-
Save cybergavin/be28addea0bde33f9ec00d685151bc5c to your computer and use it in GitHub Desktop.
SCP files from remote machine - Windows Batch script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo OFF | |
| :: --------------------------------------------------------------------- | |
| :: Script : fetchMyfiles.bat | |
| :: Description : SCP files from a remote machine. | |
| :: Requires the OpenSSH client Windows Capability to be installed (Windows Server 2019) | |
| :: --------------------------------------------------------------------- | |
| :: | |
| :: Variables | |
| :: | |
| set rootdir=D:\myfiles | |
| set sshdir=%rootdir%\ssh | |
| set pvtkey=%sshdir%\id_rsa | |
| :: Set OpenSSH client config to prefer public key authentication | |
| set sshconfig=%sshdir%\sshconfig.txt | |
| set datadir=%rootdir%\data | |
| set logfile=%rootdir%\myfiles.log | |
| set remotehost=abc.contoso.com | |
| set remoteuser=cybergavin | |
| :: | |
| :: Main | |
| :: | |
| echo %DATE% : %TIME% : INFO : Starting fetchMyfiles.bat >> %logfile% | |
| scp.exe -i %pvtkey% -F %sshconfig% %remoteuser%@%remotehost%:/Inbox/myfiles* %datadir% >> %logfile% | |
| if %ERRORLEVEL% equ 0 ( | |
| echo %DATE% : %TIME% : INFO : Fetched myfiles >> %logfile% | |
| ) else ( | |
| echo %DATE% : %TIME% : ERROR : Failed to fetch myfiles >> %logfile% | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment