Tuesday, April 8, 2014

How To Backup Files From Remote Server To Local Site


I have used WinSCP for a while to automatically backup FTP server files to local machine by using SFTP protocol. It is convenient and takes less than a few minutes to make it work with Task Scheduler on Windows 7. The greatest thing is that WinSCP requires no administrator privilege to install.

Code

P.S. Check out the documentation of Script Commands for more details.

# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Changes local working directory
lcd D:\Users\anonymous\Desktop\bkup
# Connect
open sftp://root:password@192.168.1.1 -hostkey="ssh-rsa 2048 f5:85:00:00:00:00:00:00:00:00:00:00:00:00:00:00"
# Change remote directory
cd /root/bkup
# Force binary mode transfer
option transfer binary
get -filemask="*>1d" * D:\Users\anonymous\Desktop\bkup\
# Disconnect
close
# Exit WinSCP
exit

End result

Inside the winscp.log, you should find that:

<result success="true">


Published by Ivan Chau

< ^ >