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

问题描述

我想编写WinSCP脚本来下载一个文件,放在远程服务器上每天早上4-4:30am。

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.

无论如何, :


  1. 自WinSCP 5.6.2以来提供的首选解决方案:您可以使用:

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

,上面的方法,获取所有创建日期晚于4:00的文件(%TIMESTAMP#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的简单解决方案是一个静态的依赖于相对时间的脚本:例如你知道你的脚本在上午6点运行。所以你让WinSCP下载在最后2小时(上午6点到上午4点)更新/创建的所有文件:

Easy solution for older versions of WinSCP 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


  • 使用动态脚本更困难的解决方案。基本上你需要使用你最喜欢的脚本语言(PowerShell,Perl,Python,PHP等)和生成WinSCP脚本在飞行与确切的时间戳。所以结果是(每天不同的日期):

  • More difficult solution with a dynamic script. Basically you need to make use of your favorite scripting language (PowerShell, Perl, Python, PHP, etc.) and generate WinSCP script on the fly with exact timestamps. So that the result is like (with different date every day):

    get "*.txt>2013-05-13 4:00"
    

    这相当于%TIMESTAMP%解决方案。

    有关各种语言的时间戳格式的示例,请参阅文章。

    For an example of a timestamp formatting in various languages, see article Downloading file to timestamped-filename.

    有关的文章。

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

  • 09-25 01:37