windows - 使用 Windows 批处理文件从 FTP 服务器仅下载今天的文件

标签 windows batch-file ftp timestamp

我正在尝试将 XML 文件从 FTP 位置复制到应用程序服务器 - 但不是所有文件。新文件每半小时在 ftp 位置存档一次。我只需要根据时间戳和日期传输新文件。

我目前正在使用以下 2 个文件从 FTP 位置复制所有文件。

批处理文件:

ftp -i -s:D:\ftp_commands.txt -n <host name>

文本文件 (ftp_commands.txt):

user <username> <password>
cd <source path>
lcd <destination path>
mget *
bye

谁能帮我根据时间戳或日期复制文件?

最佳答案

使用 Windows 批处理文件和内置 FTP 客户端 (ftp.exe) 来实现是一项相当复杂的任务。

使用 PowerShell 或其他更强大的语言会更容易。


使用功能更强大的 FTP 客户端更容易。

例如WinSCP FTP client支持时间限制。

使用 WinSCP,下载今天的文件的批处理文件就像:

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"

使用 WinSCP 5.13 和更新版本,语法更简单:

    "get /remote/path/*>=today C:\local\path\" ^

这使用了 %TIMESTAMP% syntax和一个 file mask with a time-constraint .

另见:

(我是 WinSCP 的作者)

关于windows - 使用 Windows 批处理文件从 FTP 服务器仅下载今天的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44663446/

相关文章:

windows - 使用单字节指令开始 x64 函数是否合法?

image - 用于将图像文件大小调整为最大大小并更改大小写的命令行工具

java - 如何使用.p12证书通过FTPClient连接到FTP?

C# FileSystemWatcher 和 FTP

PHP - 获取远程文件的 md5?

c# - Windows Phone 7 如何在枢轴项之间切换时删除 "stuttering"

windows - 将大文件合并为一个巨大的文件

windows - 复制文件而不覆盖

windows - 我怎样才能使批处理文件像使用 Perl 的简单 grep 一样运行?

windows - 使用批处理文件设置壁纸目录