上传使用腻子/ SFTP文件传输文件的时间戳 [英] Upload timestamped file using PuTTY/SFTP file transfer

查看:1327
本文介绍了上传使用腻子/ SFTP文件传输文件的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要传输文件中的帮助SFTP服务器。我们有3个阶段的脚本。

Need a help in transfer file to sftp server. We have a script with 3 stages.

驱动器

ECHO off
path\file.sftp.sc.bat

驱动器 -file.sftp.sc.bat

Driver -file.sftp.sc.bat

@ECHO OFF

set PUTTY_HOME= LOCATION\ PUTTY
set PATH=%PUTTY_HOME%;%PATH%
REM ECHO %DOWNLOADDATA1%
set DOWNLOADDATA1="N"
IF EXIST LOCATION\"FileName.txt"  SET DOWNLOADDATA1="Y"
ECHO %DOWNLOADDATA1%
IF %DOWNLOADDATA1% =="N" goto unsucc
ECHO %DOWNLOADDATA1%
ECHO GETTING DATA FILE
psftp -password -b LOCATION\Summary_LOC_SC.ftp user name
ECHO %ERRORLEVEL%
IF %ERRORLEVEL% EQU 0 LOCATION\ Success_email.vbs
goto end
IF %ERRORLEVEL% NEQ 0 LOCATION\UNSuccess_Email.vbs
goto end
:UNSUCC
ECHO %DOWNLOADDATA1%
ECHO UNSUCCESSFUL
LOCATION\UNSuccess_FNF_Email.vbs
:END

驱动器 -Summary_LOC_SC.ftp

Driver-Summary_LOC_SC.ftp

cd/fall2014
1cd LOCATION OF FILE
put "File.Txt"
quit

现在,文件名是要与日期改变,我的意思是,今天它会被file20141118.txt,明天将file20141119.txt。

Now, the file name is going to be changed with date, I mean, today it will be file20141118.txt, tomorrow will be file20141119.txt.

在上面的脚本如何实现它,所以它会拉起当前文件。

In the above script how to implement it, so it will pull up the current file.

推荐答案

如果我理解这个问题,你不知道如何修改 PSFTP 脚本,以满足动态文件名。

If I understand the problem, you do not know how to modify the psftp script to cater for dynamic file name.

您可以动态生成脚本,如:

You can generate the script on the fly like:

...
ECHO GETTING DATA FILE
echo cd/fall2014 > LOCATION\Summary_LOC_SC.ftp
echo cd LOCATION OF FILE >> LOCATION\Summary_LOC_SC.ftp
echo put "File%date:~-4,4%%date:~-7,2%%date:~-10,2%.Txt" >> LOCATION\Summary_LOC_SC.ftp
echo quit >> LOCATION\Summary_LOC_SC.ftp
psftp -password -b LOCATION\Summary_LOC_SC.ftp user name
...

请注意,上面的%DATE%神奇的是特定于语言环境。您可能需要调整。
请参照<一个href=\"http://stackoverflow.com/questions/1747468/how-to-get-a-universal-windows-batch-file-timestamp\">How得到一个万能的Windows批处理文件时间戳这里等类似的问题。

Note that the %date% magic above is locale specific. You may need to adjust it. Refer to How to get a UNIVERSAL Windows batch file timestamp and other similar questions here.

如果您已经有改名的文件名中的一些变量(我从您的意见理解,但没有看到它在code),它更容易,只需使用你的变量而不是 %DATE%

If you already have the renamed filename in some variable (what I understand from your comments, but do not see it in the code), it's easier, just use your variable instead of the %date%.

编辑:看到你的相关问题,批与当前日期的文件,只需要使用财务 答案:

Seeing your related question Batch file with current date, just use the finance variable from the answer:

echo put "%finance%" >> LOCATION\Summary_LOC_SC.ftp


或者使用 的WinSCP,而不是 PSFTP


Alternatively use WinSCP instead of psftp.

这使得code比较容易的方式感谢:

It makes the code way easier thanks to:


  • %TIMESTAMP%语法(你不需要这桩code,它生成财务时间戳名);

  • 上指定的命令行的命令,而不需要一个单独的脚本的能力。

  • its %TIMESTAMP% syntax (you won't need the awful code that generates the finance timestamped name);
  • its ability to specify commands on command-line, without need for a separate script.

例如:

...
ECHO GETTING DATA FILE
winscp.com /command ^
    "open sftp://username:password@host/" ^
    "cd /fall2014" ^
    "cd LOCATION OF FILE" ^
    "put ""File%%TIMESTAMP#yyyymmdd%%""" ^
    "exit"
...

您需要使用的WinSCP 5.6.2或更高版本的%TIMESTAMP%工作

You need to use WinSCP 5.6.2 or later for the %TIMESTAMP% to work.

参考文献:结果
http://winscp.net/eng/docs/scripting#timestamp 结果
http://winscp.net/eng/docs/guide_automation

(我的WinSCP的作者)

这篇关于上传使用腻子/ SFTP文件传输文件的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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