简体   繁体   English

如何通过 Bash 脚本在 SFTP 会话中运行命令?

[英]How Can I Run Commands In A SFTP Session Via A Bash Script?

I am trying to run the cd command in a bash script to a SFTP session.我正在尝试将 bash 脚本中的cd命令运行到 SFTP 会话。 My code currently looks like我的代码目前看起来像

#!/bin/bash
sftp $1@$2

and then I want to use cd within the SFTP session and other commands too but cd is fine for now.然后我也想在 SFTP 会话和其他命令中使用cd但现在 cd 很好。 How can I do this?我怎样才能做到这一点?

Try the batch mode.尝试批处理模式。 Quoting the man page:引用手册页:

     -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 to obviate the need to enter a
             password at connection time (see sshd(8) and ssh-keygen(1)
             for details).

             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 suppressed on a command by
             command basis by prefixing the command with a ‘-’ character
             (for example, -rm /tmp/blah*).  Echo of the command may be
             suppressed by prefixing the command with a ‘@’ character.
             These two prefixes may be combined in any order, for
             example -@ls /bsd.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM