Remote server is a Linux operating system, no FTP service, can ssh, the database will automatically create a backup file 2:00 every day, the local computer is the Windows operating system, you want to use SFTP 3:00 every day to download the backup files on the remote server. The local system is Linux, and you can refer to another article, "Automatic sftp download file under Linux".
The SFTP tool under Windows uses the Psftp.exe in the Putty Toolkit:
Http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Enter "Psftp-h" below the command line to see the use of psftp.
PuTTY Secure File Transfer (SFTP) client
Release 0.59
usage:psftp [Options] [[Email Protected]]host
Options:
-V Print version information and exit
-PGPFP print PGP key fingerprints and exit
-B file Use specified Batchfile
-BC Output Batchfile Commands
-be don ' t stop batchfile processing if errors
-V Show verbose messages
-load sessname load settings from saved session
-l user connect with specified username
-p Port Connect to specified port
-PW PASSW Login with specified password
-1-2 force use of particular SSH protocol version
-4-6 force use of IPv4 or IPV6
-C Enable compression
-I key private key file for authentication
-noagent Disable use of pageant
-agent Enable use of pageant
-batch Disable all interactive prompts
As you can see, we are able to download a file by importing a script file Sftp.txt from the completion of SFTP. The command format is as follows:
Psftp remotehost-l username-pw Password < sftp.txt
Now the problem is that the remote server's backup file is automatically created, stored in the/logs directory, the file name format is "Dumpyyyymmdd.log", such as Dump20070310.log, how can this daily changing file name be transferred to the script file Sftp.txt?
Had to Google, and finally found a can be used for batch file Date/time program realdate.com,:
Http://www.huweb.hu/maques/realdate.htm
OK, now start writing batch script Sftp.bat.
@echo off
# Write psftp required script file Sftp.txt
for/f%%i in (' realdate.com/d ') do (set remotelogname=%%i)
echo cd/logs > Sftp.txt
echo Get Dump%remotelogname%.log >> sftp.txt
echo Bye >> sftp.txt
# Write log file Sftp.log
echo--------------------------------------->> Sftp.log
for/f%%i in (' realdate.com/f= "Ccyy-mm-dd" ') do (set locallogdate=%%i)
for/f%%i in (' realdate.com/f= "Hh:mm:ss" ') do (set locallogtime=%%i)
echo%locallogdate%%locallogtime% >> Sftp.log
Psftp remotehost-l username-pw Password < sftp.txt > Sftp.log
Echo. >> Sftp.log
Echo done. >> Sftp.log
Put Psftp.exe, realdate.com, and Sftp.bat in the same folder, set up a scheduled task for Sftp.bat, and sleep at ease in the middle of the night.
######## #2
ftp/sftp automatically upload and download scriptsTags: path script userserver2012-02-13 18:50 5160 People read comments (0) favorite report This article has been included in:
Classification:SHELL
Copyright NOTICE: This article is for bloggers original article, reproduced please specify the source.
FTP script:
[Plain]View Plaincopy print?
- #! /bin/sh
- server=172.23.3.150
- remotedir=/users/tmp/
- Filename=test.txt
- Ftp-in << EOM
- Open $server
- User Username password
- Bin
- CD $remotedir
- Put $filename
- Bye
- EOM
#! /bin/shserver=172.23.3.150remotedir=/users/tmp/filename=test.txtftp-in << EOM open $server user Username Password bin cd $remotedir put $filename
SFTP script:
[Plain]View Plaincopy print?
- #!/bin/sh
- host=172.23.3.150
- User=root
- Password=1234rewq
- Filename=test.txt
- local_path=/home/ligt/windriver/
- remote_path=/users/tmp/
- Lftp-u $USER, $PASSWORD sftp://$HOST << EOM
- LCD $LOCAL _path
- CD $REMOTE _path
- Put $TARGET
- Bye
- EOM
- echo "Success!"
#!/bin/shhost=172.23.3.150user=rootpassword=1234rewqfilename=test.txtlocal_path=/home/ligt/windriver/remote_ Path=/users/tmp/lftp-u $USER, $PASSWORD sftp://$HOST << EOM LCD $LOCAL _path cd $REMOTE _path put $ TARGET Byeeomecho "success!"
Go: Automatically download files with SFTP under Windows