如何在同一个shell命令中打开sftp连接并执行sftp命令

有没有可能打开sftp连接到远程服务器,并从shell执行sftp命令在同一行。

像这样的东西:

sftp [email protected] && put /tmp/test.txt /tmp/ 

put是sftp命令。

我的想法是从本地服务器到远程服务器从远程服务器上只允许sftp的bash脚本文件。

方法1:

 echo "put /tmp/test.txt /tmp/" | sftp [email protected] 

方法2:

使用-b选项:

-bbatch file

批处理模式从inputbatch file而不是标准input读取一系列命令。 由于缺乏用户交互,因此应该与非交互式authentication一起使用。 batch file“ -' may be used to indicate standard input. sftp will abort if any of the following commands fail: get, put, rename, ln, rm, mkdir, chdir, ls, lchdir, chmod, chown, chgrp, lpwd, df, symlink, and lmkdir. Termination on error can be suppressed on a command by command basis by prefixing the command with a -' may be used to indicate standard input. sftp will abort if any of the following commands fail: get, put, rename, ln, rm, mkdir, chdir, ls, lchdir, chmod, chown, chgrp, lpwd, df, symlink, and lmkdir. Termination on error can be suppressed on a command by command basis by prefixing the command with a -' may be used to indicate standard input. sftp will abort if any of the following commands fail: get, put, rename, ln, rm, mkdir, chdir, ls, lchdir, chmod, chown, chgrp, lpwd, df, symlink, and lmkdir. Termination on error can be suppressed on a command by command basis by prefixing the command with a – ”字符(例如-rm / tmp / blah *), -' may be used to indicate standard input. sftp will abort if any of the following commands fail: get, put, rename, ln, rm, mkdir, chdir, ls, lchdir, chmod, chown, chgrp, lpwd, df, symlink, and lmkdir. Termination on error can be suppressed on a command by command basis by prefixing the command with a