如何从批处理文件中执行 WinSCP 命令

How to execute WinSCP commands from a batch file

我想知道是否有办法从批处理文件中 运行 WinSCP 命令,如 open sftp...,而无需在 WinSCP 打开后输入命令。

这是我想要发生的事情:

  1. 我创建了一个打开 WinSCP 命令行的批处理文件(比如 demo.bat)。
  2. 我在 demo.bat.
  3. 中插入 WinSCP 命令(opengetput 等)
  4. 批处理文件demo.bat打开WinSCP命令行并自动执行命令(getput等)。

使用/command or /script command-line switches.

有一个guide to automating file transfers to SFTP server with WinSCP

使用 /command 开关的简单批处理文件如下:

WinSCP.com ^
  /log="C:\writable\path\to\log\WinSCP.log" /ini=nul ^
  /command ^
    "open sftp://username:password@example.com/" ^
    "put C:\local\path\file.txt /remote/path/" ^
    "exit"

而 WinSCP GUI 实际上甚至可以 generate the batch file for you: