批处理文件下载名称以FTP中给定字符串开头的文件 [英] Batch file to download a file with name that starts with a given string from FTP
问题描述
我使用以下bat文件:
:: @ echo off
cd / d%0 \ ..
set cmd =%CD%
echo user%〜2> %cmd%\ftpcmd.dat
echo%〜3>> %cmd%\ftpcmd.dat
echo bin>> %cmd%\ftpcmd.dat
IF NOT%5==echo cd%〜5>> %cmd%\ftpcmd.dat
echo get%〜4%cmd%\%〜4>> %cmd%\ftpcmd.dat
echo quit>> %cmd%\ftpcmd.dat
ftp -n -s:%cmd%\ftpcmd.dat%1
del%cmd%\ftpcmd.dat
$ c $ c:\download.bat ftpHost登录密码file.xml FTP_FOLDER
正如你所看到的这个脚本复制具有特定名称的文件。
如何更改此脚本以查找以某个字符串开头的第一个XML文件。因此,而不是 file.xml
我希望通过 beginning_of_the_string
(没有 .xml
)。那么脚本应该复制这些文件的第一个文件?
解决方案 Windows ftp.exe
不支持通配符。
您可以运行 ftp.exe
分两个阶段。首先列出远程目录。然后,您在本地处理列表以查找具有给定前缀的文件。然后再次运行 ftp.exe
以下载文件。
<或者使用另一个支持通配符匹配的FTP客户端。
例如您可以使用 WinSCP :
@echo off
cd / d%0 \ ..
set cmd =%CD%
echo open ftp://%〜2:% 〜3%1> %cmd%\ftpcmd.dat
IF NOT%5==echo cd%〜5>> %cmd%\ftpcmd.dat
echo get%〜4%cmd%\>> %cmd%\ftpcmd.dat
回显退出>> %cmd%\ftpcmd.dat
%cmd%\winscp.com /script=%cmd%\ftpcmd.dat
del%cmd%\ftpcmd.dat
code>
你可以这样称呼它:
c:\download.bat ftpHost登录密码beginning_of_the_string * .xml FTP_FOLDER
而不是 beginning_of_the_string * .xml
,使用任何其他文件掩码/通配符,WinSCP支持。
有关详细信息,请参阅 WinSCP脚本。
(我是WinSCP的作者)
I use the following bat file:
::@echo off
cd /d %0\..
set cmd=%CD%
echo user %~2> %cmd%\ftpcmd.dat
echo %~3>> %cmd%\ftpcmd.dat
echo bin>> %cmd%\ftpcmd.dat
IF NOT "%5" == "" echo cd %~5>> %cmd%\ftpcmd.dat
echo get %~4 %cmd%\%~4>> %cmd%\ftpcmd.dat
echo quit>> %cmd%\ftpcmd.dat
ftp -n -s:%cmd%\ftpcmd.dat %1
del %cmd%\ftpcmd.dat
Parameters and executions are like below:
c:\download.bat ftpHost login password file.xml FTP_FOLDER
As you can see this script copy file with the specific name.
How can I change this script to look for the first XML file that starts with a certain string. So instead of file.xml
I want pass beginning_of_the_string
(without .xml
). Then script should copy the first of these files?
解决方案 The Windows ftp.exe
does not support wildcards.
You can run the ftp.exe
in two phases. First to list the remote directory. Then you locally process the list to find a file with given prefix. And then run the ftp.exe
again to download the file.
Or use another FTP client that supports wildcard matching.
E.g. with WinSCP you can do:
@echo off
cd /d %0\..
set cmd=%CD%
echo open ftp://%~2:%~3@%1 > %cmd%\ftpcmd.dat
IF NOT "%5" == "" echo cd %~5 >> %cmd%\ftpcmd.dat
echo get %~4 %cmd%\ >> %cmd%\ftpcmd.dat
echo exit >> %cmd%\ftpcmd.dat
%cmd%\winscp.com /script=%cmd%\ftpcmd.dat
del %cmd%\ftpcmd.dat
And you call it like:
c:\download.bat ftpHost login password beginning_of_the_string*.xml FTP_FOLDER
Instead of the beginning_of_the_string*.xml
, use any other file mask/wildcard that WinSCP supports.
For details, see the guide to WinSCP scripting.
(I'm the author of WinSCP)
这篇关于批处理文件下载名称以FTP中给定字符串开头的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文