批处理文件从FTP服务器下载最新的文件 [英] Batch file to download the latest file from FTP server
问题描述
我有一个批处理文件,可以从我的网络服务器获取FTP CSV文件。
我只需要下载最新的CSV文件。
我该怎么做?
这是我到目前为止:
打开44.44。 44.444
用户名
密码
CD /客户端/ ABCCompany /
获取* .csv
退出
close()
谢谢。
使用 如果您知道该文件的文件名中包含当前的时间戳,则可以使用今天的动态脚本动态生成脚本时间戳。您可以使用 WinSCP 可以使用 另见指南使用WinSCP下载最新文件。 WinSCP还可以在一段时间内下载创建的文件,例如最后24小时(1天): 或某些时间点后创建的文件,例如从午夜开始,使用 使用WinSCP,您可以更轻松地实现带有时间戳的文件下载与 (我是WinSCP的作者) I have a batch file that FTPs CSV files from my web server.
I need to download only the most current CSV file. How do I do that? This is what I have so far: Thanks. There's no easy way to select the most recent file with the If you know that the file has today's timestamp in its filename, you can generate the script dynamically with today's timestamp. You can use the See How to get current datetime on Windows command line, in a suitable format for using in a filename? If you can determine the latest file alphabetically, you can: WinSCP can download the latest file, using the See also the guide to downloading the most recent file with WinSCP. WinSCP can also download the files created within some interval, e.g. the last 24-hours (1 day): or files created since some point in time, e.g. since midnight, using the With WinSCP, you can implement a download of a file with a timestamp in filename more easily than with the (I'm the author of WinSCP) 这篇关于批处理文件从FTP服务器下载最新的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! ftp.exe $ c选择最近的文件并不容易
DATE
环境变量,尽管它有一些注意事项。一个更可靠的方法是使用 wmic os get LocalDateTime
。
如果您可以按字母顺序确定最新的文件, ftp.exe
, ls
命令重定向到文件
ftp.exe
运行的下载脚本。 li>
-latest
下载最新的文件,切换 获取
命令(WinSCP 5.9和更新版本):
winscp.com / command ^
open ftp:// username:password@ftp.example.com/^
cd / remote / path^
get -latest * .csv^
exit
winscp.com /命令^
open ftp://用户名:password@ftp.example.com/^
cd / remote / path^
get * .csv> = 1D^
exit
%TIMESTAMP%
语法:
winscp.com /命令^
open ftp:// username:password @ ftp .example.com /^
cd / remote / path^
get * .csv> = %% TIMESTAMP#yyyy-mm-dd %%^
exit
DATE
或 wmic os获得LocalDateTime
(如上所示)相比。再次使用%TIMESTAMP%
语法:
winscp.com /命令^
open ftp:// username:password@ftp.example.com/^
cd / remote / path^
get %% TIMESTAMP#yyyy-mm-dd %%。txt^
exit
open 44.44.44.444
username
password
CD /Client/ABCCompany/
get *.csv
quit
close()
ftp.exe
.
DATE
environment variable, though it has its caveats. A more reliable (and complex) way is to use the wmic os get LocalDateTime
.
ftp.exe
with ls
command redirected to a fileftp.exe
run.
-latest
switch of the get
command (WinSCP 5.9 and newer only):winscp.com /command ^
"open ftp://username:password@ftp.example.com/" ^
"cd /remote/path" ^
"get -latest *.csv" ^
"exit"
winscp.com /command ^
"open ftp://username:password@ftp.example.com/" ^
"cd /remote/path" ^
"get *.csv>=1D" ^
"exit"
%TIMESTAMP%
syntax:winscp.com /command ^
"open ftp://username:password@ftp.example.com/" ^
"cd /remote/path" ^
"get *.csv>=%%TIMESTAMP#yyyy-mm-dd%%" ^
"exit"
DATE
or the wmic os get LocalDateTime
(as shown above). Again use the %TIMESTAMP%
syntax:winscp.com /command ^
"open ftp://username:password@ftp.example.com/" ^
"cd /remote/path" ^
"get %%TIMESTAMP#yyyy-mm-dd%%.txt" ^
"exit"