Automate file transfers (or synchronization) to FTP server or SFTP serve
Script.bat
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
@echo off :: log folder SET Folder="C:\var\log\" IF EXIST %Folder%*.txt ( rem file exist :: ECHO %F% is existing echo y| move %Folder%*.txt %Folder%temp\ winscp.com /ini=nul /script=C:\"Program Files (x86)"\WinSCP\Log_SFTP.txt if %ERRORLEVEL% neq 0 goto error echo Success :: echo y| del %Folder%temp\*.txt echo y| move %Folder%temp\*.txt %Folder%log\ exit /b 0 :error echo Error! echo "Error............" exit /b 1 ) |
Log_SFTP.txt
1 2 3 4 5 6 7 8 |
# Connect to SFTP server using a password open sftp://ID:Password@111.222.222.222:2525 -hostkey="ssh-ed25519 256 **********************************=" # Upload file put %Folder%temp\*.txt /uploads/ # Exit WinSCP exit |
예제 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
@echo off :: log folder SET Folder="D:\Log" SET yyyymmdd=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2% IF EXIST %Folder%\%yyyymmdd%\*.xml ( rem file exist :: ECHO %F% is existing echo y| move %Folder%\%yyyymmdd%\*.log %Folder%\Temp\ winscp.com /ini=nul /script=C:\"Program Files (x86)"\WinSCP\Log_SFTP.txt if %ERRORLEVEL% neq 0 goto error echo Success :: echo y| del %Folder%temp\*.txt echo y| move %Folder%\Temp\*.log %Folder%\Log\ exit /b 0 :error echo Error! echo "Error............" exit /b 1 ) |
1 2 3 4 5 6 7 8 9 |
# Connect to SFTP server using a password open ftp://MYID:MYPASSWORD@111.222.111.222:54325 -passive=on # Upload file # put %Folder%\%yyyymmdd%\ / put %Folder%\Temp\*.log /%yyyymmdd%/ # Exit WinSCP exit |