使用Windows批处理文件从FTP服务器下载今天的文件 [英] Download only today's files from FTP server using Windows batch file

查看:194
本文介绍了使用Windows批处理文件从FTP服务器下载今天的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将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:

(I'm the author of WinSCP)

这篇关于使用Windows批处理文件从FTP服务器下载今天的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆