我正在尝试将 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 客户端 https://winscp.net/支持时间限制。
使用 WinSCP,下载今天的文件的批处理文件就像以下一样简单:
winscp.com /ini=nul /log=todays.log /command ^
"open ftp://username:[email protected] /cdn-cgi/l/email-protection/" ^
"get /remote/path/*>=%%TIMESTAMP#yyyy-mm-dd%% C:\local\path\" ^
"exit"
使用 WinSCP 5.13 及更高版本,语法更加简单:
"get /remote/path/*>=today C:\local\path\" ^
这使用了%TIMESTAMP% syntax https://winscp.net/eng/docs/scripting#timestamp and a 具有时间限制的文件掩码 https://winscp.net/eng/docs/file_mask#size_time.
也可以看看:
- 指南将 Windows FTP 脚本转换为 WinSCP 脚本 https://winscp.net/eng/docs/guide_ftp_script_to_sftp;
-
使用 WinSCP 下载最新文件 https://winscp.net/eng/docs/script_download_most_recent_file.
(我是WinSCP的作者)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)