Go: Automatically download files with SFTP under Windows

Source: Internet
Author: User

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?
    1. #! /bin/sh
    2. server=172.23.3.150
    3. remotedir=/users/tmp/
    4. Filename=test.txt
    5. Ftp-in << EOM
    6. Open $server
    7. User Username password
    8. Bin
    9. CD $remotedir
    10. Put $filename
    11. Bye
    12. 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?
    1. #!/bin/sh
    2. host=172.23.3.150
    3. User=root
    4. Password=1234rewq
    5. Filename=test.txt
    6. local_path=/home/ligt/windriver/
    7. remote_path=/users/tmp/
    8. Lftp-u $USER, $PASSWORD sftp://$HOST << EOM
    9. LCD $LOCAL _path
    10. CD $REMOTE _path
    11. Put $TARGET
    12. Bye
    13. EOM
    14. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.