Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 使用WinSCP使用SFTP上载时间戳文件_Batch File_Sftp_Winscp - Fatal编程技术网

Batch file 使用WinSCP使用SFTP上载时间戳文件

Batch file 使用WinSCP使用SFTP上载时间戳文件,batch-file,sftp,winscp,Batch File,Sftp,Winscp,我正在制作一个批处理文件,以便将文件上载到SFTP服务器上的一个特定文件夹。当我使用task scheduler运行文件时,它不会显示任何错误,但不会在客户端的SFTP文件夹中上载任何内容。以下是我的批处理脚本: @echo off REM Defines an exiting variable to be added onto each file giving it a time-stamp and exiting the current instance of WinSCP. set d=

我正在制作一个批处理文件,以便将文件上载到SFTP服务器上的一个特定文件夹。当我使用task scheduler运行文件时,它不会显示任何错误,但不会在客户端的SFTP文件夹中上载任何内容。以下是我的批处理脚本:

@echo off

REM Defines an exiting variable to be added onto each file giving it a time-stamp and exiting the current instance of WinSCP.
set d=%date:~-4,4%%date:~4,2%%date:~-7,2%
set d=%d: =_%

REM Creates the variable lines to shorten the SFTP file upload.
REM Example usage --> %transferStart%ourFile.txt %transferEnd%TheirFile.txt%e%
SET upload=winscp.exe /console /command "option confirm off" "open sftp://user:pass@example.com" "c:\apps\ftpfiles\name_%d%.txt" "put \\mainfolder\inbound\" "close"

批处理文件中有很多问题。我至少可以确定:

  • 您设置了环境变量
    upload
    (出于我不理解的原因),但没有使用它。直接调用WinSCP:

    winscp.exe /console /command ...
    
  • 虽然并非完全错误,但从批处理文件中使用
    winscp.exe
    (GUI应用程序)会使调试复杂化(它会启动一个单独的窗口或winscp进程)。改用新的。对于
    winscp.com
    /console
    参数是冗余的:

    winscp.com /command ...
    
  • 您可以将文件名
    “c:\apps\ftpfiles\name\u%d%.txt”
    当作命令来使用。如果要上载此特定文件,请使用中的路径:

  • 您缺少to中的
    -hostkey
    开关

  • 您缺少(
    退出
    之前的
    关闭
    是多余的)

  • date
    环境变量获取时间戳是不可靠的(
    date
    的值是特定于区域设置的)。使用WinSCP:

    (对于
    %TIMESTAMP%
    ,您需要使用WinSCP 5.7或更高版本)

  • 使用最新版本的WinSCP

所有这些应用,您的批处理文件将由单个命令组成:

@echo off

winscp.com /command ^
    "open sftp://user:pass@example.com -hostkey=""your-servers-hostkey""" ^
    "put c:\apps\ftpfiles\name_%%TIMESTAMP#yyyymmdd%%.txt" ^
    "exit"

你是否在结尾处缺少结束语?不,在原始版本中,我有结束语代码,我在这里也添加了结束语代码。谢谢你让我知道。我在代码中有它,仍然没有结果。我还添加了“-hostkey=“ssh rsa 22 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx“在我的sftp open语句的末尾,但它没有改变任何东西
c:\apps:\ftpfiles\name\uu%d%.txt
apps
之后有一个
无效。感谢您的回复。”。我使用了您提供的时间戳,但在添加此项时,任务计划程序给我的函数不正确。%时间戳#yyyymmdd%对不起,这很模糊。“任务计划程序给我的函数不正确”是什么意思?这是任务上次运行结果中的消息:“函数无效”。我刚刚注意到我们正在使用WinSCP 5.1.1。这个%TIMESTAMP#yyyymmdd%是否也适用于这个版本?不,不是。这就是为什么我明确提到,您需要使用WinSCP5.7或更高版本。虽然我不认为“无效函数”消息与此相关。
"put c:\apps\ftpfiles\name_%TIMESTAMP#yyyymmdd%.txt"
@echo off

winscp.com /command ^
    "open sftp://user:pass@example.com -hostkey=""your-servers-hostkey""" ^
    "put c:\apps\ftpfiles\name_%%TIMESTAMP#yyyymmdd%%.txt" ^
    "exit"