[Windows] Quick Download batch script for latest software package from FTP

Source: Internet
Author: User

Background

Due to agile development and rapid iteration, our project will have three versions a day, which means I have to get three packages a day. I am responsible for server development, so I often need to get the latest client. Our client is placed on a public ftp top. Frequent ftp download every day, or the use of FTP tools, every time you have to click Sync, are not very convenient. If it's good under Linux, but you can run the script in Windows, why not try it.

Full code
1 @echo off2 REMFor download file3 REMFTP config4 REMIP login_name Password remote_dir5 6 Set"ftp_ip=192.168.0.1"7 Set"Ftp_user=admin"8 Set"Ftp_pass=123456"9 Set"Ftp_path=/"Ten  One Set"F_tmp=tmp" A Set"F_info=tmp\tmp_info.dat" - Set"F_list=tmp\tmp_list.dat" -  the Rd/S/Q Pack - mkdir%f_tmp% -  - EchoOpen%ftp_ip% >%f_info% + EchoUser%ftp_user% >>%f_info% - Echo%ftp_pass%>>%f_info% + Echo prompt>>%f_info% A EchoBinary >>%f_info% at Echo CD%ftp_path% >>%f_info% - EchoLs. %f_list% >>%f_info% - EchoLCD%f_tmp% >>%f_info% - EchoDisconnect >>%f_info% - EchoBye >>%f_info% -  in ftp-v-n-s:%f_info% -  to  +  for/F "delims="%%i in ('type"%f_list%") Do( -     Set"Target_7z=%%i" the) *  $ EchoOpen%ftp_ip% >%f_info%Panax Notoginseng EchoUser%ftp_user% >>%f_info% - Echo%ftp_pass%>>%f_info% the Echo prompt>>%f_info% + EchoBinary >>%f_info% A Echo CD%ftp_path% >>%f_info% the EchoLCD%f_tmp% >>%f_info% + EchoGet%target_7z%>>%f_info% - EchoDisconnect >>%f_info% $ EchoBye >>%f_info% $  - ftp-v-n-s:%f_info% -  the PagerTools\7z\x64\7za.exe x%f_tmp%\%target_7z% - Wuyi Rd/S/Q%f_tmp% the  - Exit
batch-processing scripts
Run the script

Step through the Get file list
EchoOpen%ftp_ip% >%f_info%EchoUser%ftp_user% >>%f_info%Echo%ftp_pass%>>%f_info%Echo prompt>>%f_info%EchoBinary >>%f_info%Echo CD%ftp_path% >>%f_info%EchoLs. %f_list% >>%f_info%EchoLCD%f_tmp% >>%f_info%EchoDisconnect >>%f_info%EchoBye >>%f_info%ftp-v-n-s:%f_info%

This part of the code mainly has the following functions:

      1. Writes the FTP command to the file;
      2. Get a list of files for the corresponding directory on FTP and write to the local file.
Get the latest file
 for/F "delims="%%i in ('type does (    set "target_7z=%%i")

It then loops through the list of files and eventually gets to the last list (that is, the most recent file name).

Download the latest file
EchoOpen%ftp_ip% >%f_info%EchoUser%ftp_user% >>%f_info%Echo%ftp_pass%>>%f_info%Echo prompt>>%f_info%EchoBinary >>%f_info%Echo CD%ftp_path% >>%f_info%EchoLCD%f_tmp% >>%f_info%EchoGet%target_7z%>>%f_info%EchoDisconnect >>%f_info%EchoBye >>%f_info%ftp-v-n-s:%f_info%

With the file name, we can execute the ftp command again, download our latest file. The above is to achieve dynamic download the latest files.

Extract

The packages we use here are packaged in 7z. So also download 7z unzip tool.
Official address: http://www.7-zip.org/
Then download to the command-line version and place it in any readable directory.

 call Tools\7z\x64\7za.exe x%f_tmp%\%target_7z%
Something

Normally used to Daoteng under Linux. You can write some scripts to do some tedious things, but in Windows often dumbfounded. There are many advantages to visualizing things, but there are some drawbacks. The batch script is not available, although it is not working well. A lot of times can also bring great convenience. Of course, Python, Ruby, these scripting languages are actually perfectly satisfying. After all, the current batch of this kind of thing has been used more and more less. windows shellYes, but it doesn't feel good either.

Resources
      • http://occool.com/2012/03/"reprint" command line compression decompression 7z/
      • http://www.robvanderwoude.com/ftp.php

[Windows] Quick Download batch script for latest software package from FTP

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.