您可以使用 sftp 的“批处理模式”。来自手册:
> -b batchfile
> Batch mode reads a series of commands from an input batchfile instead of stdin. Since it lacks user interaction it
> should be used in conjunction with non-interactive authentication. A batchfile of ‘-’ may be used to indicate
> standard input. sftp will abort if any of the following commands fail: get, put, reget, reput, rename, ln, rm,
> mkdir, chdir, ls, lchdir, chmod, chown, chgrp, lpwd, df, symlink, and lmkdir. Termination on error can be sup‐
> pressed on a command by command basis by prefixing the command with a ‘-’ character (for example, -rm /tmp/blah*).
这意味着,您使用命令创建一个临时文件,并使用“sftp -b tempfile user@server”执行文件中的命令
还有其他工具可以完成此类操作,例如 lftp