加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-14 02:44:23 所属栏目:Linux 来源:网络整理
导读:是否有可能打开sftp连接到远程服务器并从 shell执行同一行中的sftp命令. 像这样的东西: sftp user@example.com put /tmp/test.txt /tmp/ 其中put是sftp命令. 我的想法是从bash脚本将文件从本地服务器放到远程服务器,在远程服务器上只允许sftp. 解决方法 方
是否有可能打开sftp连接到远程服务器并从 shell执行同一行中的sftp命令.

像这样的东西:

sftp user@example.com && put /tmp/test.txt /tmp/

其中put是sftp命令.

我的想法是从bash脚本将文件从本地服务器放到远程服务器,在远程服务器上只允许sftp.

解决方法

方法1:
echo "put /tmp/test.txt /tmp/" | sftp user@example.com

方法2:

使用-b选项:

-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,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-‘ character (for example,-rm /tmp/blah*).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读