【问题标题】:Monitoring changes on SFTP server with WinSCP and batch使用 WinSCP 和批处理监视 SFTP 服务器上的更改
【发布时间】:2021-11-26 09:56:17
【问题描述】:

我想监控我们的 SFTP,以便在添加文件时向我们发送电子邮件。现在我尝试使用批处理脚本为if/else 设置条件,但批处理环境不接受我的条件。

我是批处理和自动化的新手,所以我首先尝试将 SFTP 文件与本地文件同步,然后运行批处理计划以尝试再次同步;如果确实如此,那么它将发送 na 电子邮件(我目前没有为电子邮件制作脚本,老实说我现在不知道该怎么做),如果它没有同步则退出脚本。

这是我的脚本:

option batch on
option confirm off
open sftp://x@sftp.x/ -privatekey=privateKey.ppk -hostkey="ssh-rsa 2048 x"
option transfer binary
if synchronize local "C:\Users\Administrateur\Desktop\x\x" "/x/x/rx" (
ECHO nouveau fichier ajouter au repertoir
)
else (ECHO aucun nouveau fichier exit
)

这是错误:

Commande inconnue 'if'.

【问题讨论】:

    标签: windows batch-file cmd sftp winscp


    【解决方案1】:
    • 添加-preview switch to your synchronize command 使其仅检查更改,而不是实际同步文件。

    • option failonnomatch on 添加到您的脚本中,使synchronize 命令报告没有差异作为错误。

      option failonnomatch on
      synchronize -preview local "C:\Users\Administrateur\Desktop\x\x" "/x/x/rx"
      
    • 在实际的批处理文件中,check WinSCP exit code 判断,是否有差异。像这样的:

      winscp.com /script=script.txt /log=script.log
      if errorlevel 1 (
        echo Nothing to synchronize or other problem
      ) else (
        echo There are files to synchronize
      )
      

      如果您想发送电子邮件,请参阅 Emailing script results 的 WinSCP 指南。

    【讨论】:

      猜你喜欢
      • 2013-04-20
      • 2011-11-14
      • 2013-11-17
      • 2016-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-24
      • 2020-10-02
      相关资源
      最近更新 更多