In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to use FTP command to download bat files automatically in batches". In daily operation, I believe many people have doubts about how to use FTP commands to automatically download bat files in batches. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts of "how to use FTP commands to download bat files automatically in batches". Next, please follow the editor to study!
FTP does not support directory downloads, but the FTP command provides the mget command, which allows multiple file downloads, but each file download requires confirmation and cannot be completed automatically. This paper mainly introduces the use of batch processing, combined with the relevant commands of FTP to achieve batch file download, in order to achieve the purpose of directory download.
The general idea is as follows:
Ftp-s:filename hosts > result.txt executes the script and directs the output to result.txt
The contents of the script, such as
Cd mydir
Ls
Bye
You can list mydir commands
Then use batch processing to analyze result.txt
From 150 Opening ASCII mode data connection for file list. Until 226th Transfer complete is the content to be downloaded
Then use batch processing plus ftp script, use get command to download one by one
However, in the actual process, it is found that there is a problem with using get in the FTP script, prompting that the parameters are wrong and cannot be used.
Checked ftp's help ftp -?
G: > ftp -?
Transfers files to and from a computer running an FTP server service
(sometimes called a daemon). Ftp can be used interactively.
FTP [- v] [- d] [- I] [- n] [- g] [- s:filename] [- a] [- w:windowsize] [- A] [host]
-v Suppresses display of remote server responses.
-n Suppresses auto-login upon initial connection.
-i Turns off interactive prompting during multiple file
Transfers.
-d Enables debugging.
-g Disables filename globbing (see GLOB command).
-s:filename Specifies a text file containing FTP commands; the
Commands will automatically run after FTP starts.
-a Use any local interface when binding data connection.
-A login as anonymous.
-w:buffersize Overrides the default transfer buffersize of 4096.
Host Specifies the host name or IP address of the remote
Host to connect to.
Notes:
-mget and mput commands take y/n/q for yes/no/quit.
-Use Control-C to abort commands.
It is found that the-I parameter can remove the prompt of mget. After testing, the following script is implemented (anonymous login is used. If it is not anonymous, the login script can be modified):
Echo cd autoruns > ftp.txt
Echo mget * > ftp.txt
Echo bye > > ftp.txt
Ftp-I-A-s:ftp.txt 10.1.103.10
However, this only downloads the files in the directory, and if you have a subdirectory, you also need to use the dir command to output, and turn to output to text, and use find to extract the directory, such as:
Echo cd autoruns > ftp.txt
Echo dir > > ftp.txt
Echo bye > > ftp.txt
Ftp-A-s:ftp.txt 10.1.103.10 | find "" > result.txt
For / f "tokens=2,3*" I in (result.txt) do echo k
If you have subfolders, you need to write them in depth.
After writing and testing, the following script is implemented, and the running environment WINXP SP2 has passed, but has not been tested on other systems:
1. The main script, ftpget.bat, changes the relevant information of the first four variables. This script calls makeTree.bat, see 2.
Rem FTP server address
Set host=10.1.103.10
Login name of rem FTP. You don't need to change it if you are anonymous.
Set user=anonymous
Rem FTP login password. You don't have to change it if you are anonymous.
Set pass=123456
Rem needs to download the FTP directory, if you download the subdirectory to divide the grid
Set dirname= directory 1 subdirectory
Set homedir=%cd%
Rem generates FTP directory structure
Del tree.txt
Start / w cmd / c makeTree dirname% 0
Del result*.txt
For / f "delims=/"% I in (tree.txt) do (
Rem gets all the files of dirname
Rem = =
Cd homedir%
Md I
Cd / d% I
Echo user% > ftp.txt
Echo pass% > > ftp.txt
Echo cd I > > ftp.txt
Rem mget *. * download all files, but not files without an extension
Rem can download all the files if you use mget *, but it will also download the files from the subdirectory.
Echo mget *. * > ftp.txt
Echo bye > > ftp.txt
Ftp-I-A-s:ftp.txt% host%
Del ftp.txt
Rem = =
)
Cd homedir%
Del tree.txt
2. Maketree.bat to generate FTP directory tree
Rem generates FTP directory structure
Rem calls method maketree dir1dir2 n (n > = 1)
Rem% 1 = = dir1dir2
Rem% 2 = = n
Set / a treetime=%2+1
Echo 1 > > tree.txt
Echo user% > ftp%treetime%.txt
Echo pass% > > ftp%treetime%.txt
Echo cd 1 > > ftp%treetime%.txt
Echo dir > > ftp%treetime%.txt
Echo bye > > ftp%treetime%.txt
Ftp-A-s:ftp%treetime%.txt% host% | find "" > result%treetime%.txt
For / f "tokens=2,3*"%% I in (result%treetime%.txt) do (start / w cmd / c Maketree.bat% 1% k% treetime%)
Del result%treetime%.txt
Del ftp%treetime%.txt
At this point, the study on "how to use the FTP command to download bat files automatically in batches" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.