使用Windows批处理文件从FTP服务器下载今天的文件 [英] Download only today's files from FTP server using Windows batch file
问题描述
我试图将XML文件从FTP位置复制到应用程序服务器 - 但不是所有文件。新文件在ftp位置每隔半小时存档一次。我只需要根据时间戳和日期传输新文件。
我目前使用以下2个文件从FTP位置复制所有文件。
批处理文件:
ftp -i -s:D:\ ftp_commands.txt -n<主机名>
文本文件(ftp_commands.txt):
用户<用户名> <密码>
cd<源路径>
lcd<目的地路径>
mget *
bye
任何人都可以帮助我根据时间戳复制文件或日期?
使用Windows批处理文件和内置FTP客户端( ftp.exe
)。
使用PowerShell或其他更强大的语言会更容易。
使用功能更强大的FTP客户端更容易。 例如 WinSCP FTP客户端支持时间限制。
使用WinSCP,一个批处理文件下载今天的文件并不重要:
winscp.com / ini = nul /log=todays.log/命令^
open ftp:// username:password@ftp.example.com/^
get / remote / path / *> = %% TIMESTAMP#yyyy-mm-dd %% C:\\ \\本地\路径\^
退出
这使用 %TIMESTAMP%
语法和具有时间限制的文件掩码。
另请参阅:
(我是WinSCP的作者)
I am trying to copy XML files from an FTP location to an application server - but not all files. New files are archived after every half an hour in the ftp location. I need to transfer only the new files based on the timestamp and date.
I am currently using the below 2 files to copy all the files from FTP location.
Batch file:
ftp -i -s:D:\ftp_commands.txt -n <host name>
Text file (ftp_commands.txt):
user <username> <password>
cd <source path>
lcd <destination path>
mget *
bye
Can anyone please help me copy files based on timestamp or date?
It's a pretty complex task to implement with Windows batch-file and the built-in FTP client (ftp.exe
).
It would be more easier with PowerShell or other more powerful language.
And even easier using a more capable FTP client.
For example WinSCP FTP client supports time constraints.
With WinSCP, a batch file to download today's files is as trivial as:
winscp.com /ini=nul /log=todays.log /command ^
"open ftp://username:password@ftp.example.com/" ^
"get /remote/path/*>=%%TIMESTAMP#yyyy-mm-dd%% C:\local\path\" ^
"exit"
This uses the %TIMESTAMP%
syntax and a file mask with a time-constraint.
See also:
- guide for Converting Windows FTP script to WinSCP script;
- Downloading the most recent file with WinSCP.
(I'm the author of WinSCP)
这篇关于使用Windows批处理文件从FTP服务器下载今天的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!