WinSCP 基于时间的文件下载 [英] WinSCP time based file download

查看:45
本文介绍了WinSCP 基于时间的文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写 WinSCP 脚本来下载每天早上 4 点到 4 点 30 分之间放置到远程服务器上的文件.有没有办法通过时间戳来做到这一点?

I would like to write WinSCP script to download a file that is placed onto the remote server every morning between 4-4:30am. Is there a way to do this with time-stamping?

我想伪代码:

get file.txt where timestap<1 hour from 4 am

推荐答案

首先,我假设您的文件没有固定名称(与固定名称 file.txt 的问题相反).如果不是,请解释为什么需要基于时间戳的解决方案.

First, I assume your file does not have fixed name (contrary to your question with fixed name file.txt). If not, please explain, why do you need timestamp-based solution.

无论如何,您可以使用有时间限制的文件掩码:>

Anyway, you can use a file mask with a time constraint:

get "*.txt>2014-07-19 4:00"

要动态注入今天的日期,请使用 %TIMESTAMP% 语法:

To dynamically inject today's date, use the %TIMESTAMP% syntax:

get "*.txt>%TIMESTAMP#yyyy-mm-ss% 4:00"

简单来说,上面的意思是,获取今天 4:00 之后创建的所有文件(%TIMESTAMP#yyyy-mm-ss% 解析为今天的日期,格式为 yyyy-mm-ss,根据时间限制的需要).

Simply, the above means, get all files created later than 4:00 today (the %TIMESTAMP#yyyy-mm-ss% resolves to today's date in format yyyy-mm-ss, as needed for the time constraint).

在批处理文件中在 WinSCP 命令行上传递 get 时(使用 /command 开关,与使用 /script 开关相反要指定单独的脚本文件),您必须将 % 加倍以避免批处理文件试图解释 %TIMESTAMP%:

When passing the get on WinSCP command-line in a batch file (using /command switch, as opposite to using /script switch to specify a separate script file), you have to double the % to avoid the batch-file trying to interpret the %TIMESTAMP%:

winscp.com /command ... "get ""*.txt>%%TIMESTAMP#yyyy-mm-ss%% 4:00"""

<小时>

另一种解决方案是依赖相对时间的静态脚本:例如你知道你的脚本在早上 6 点运行.因此,您让 WinSCP 下载过去 2 小时(早上 6 点至凌晨 4 点)内更新/创建的所有文件:


Another solution is a static script that rely on a relative time: E.g. you know your script runs at 6am. So you let WinSCP download all files updated/created in the last 2 hours (6am – 4am):

get *.txt>2h

<小时>

另见关于下载最新文件的WinSCP文章.

这篇关于WinSCP 基于时间的文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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