使用 Mac OS X 的 Bash 脚本中的 SFTP 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9102557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:27:51  来源:igfitidea点击:

SFTP command in Bash script with Mac OS X

macosbashsshsftp

提问by Tiit Remmel

I need to transfer a text file to a remote PC (freeSSH) using SFTP and SSH from a Mac host. These two are connected in a local network.

我需要使用 SFTP 和 SSH 从 Mac 主机将文本文件传输到远程 PC (freeSSH)。这两个连接在本地网络中。

So is there a way to run an SFTP command (with the username and password provided) from inside the Bash script?

那么有没有办法从 Bash 脚本内部运行 SFTP 命令(使用提供的用户名和密码)?

I already tried some scripting with expect, but I didn't get any results.

我已经尝试了一些脚本expect,但没有得到任何结果。

I found a similar post, How to run the sftp command with a password from a Bash script, but it is for Linux. I have a Mac.

我找到了一个类似的帖子,How to run the sftp command with a password from a Bash script,但它适用于 Linux。我有一台 Mac。

采纳答案by anubhava

You can download and install sshpass on Mac as well. Get the latest version source from this download link

您也可以在 Mac 上下载并安装 sshpass。从此下载链接获取最新版本源

Rest of the steps on using sshpass are there in the linked answer of mine.

使用 sshpass 的其余步骤在我的链接答案中。

回答by kqw

lftpis great for scripting ftp (and sftp, ftps). And you can install it with brew:

lftp非常适合编写 ftp(和 sftp、ftps)脚本。你可以用brew安装它:

brew install lftp

回答by Greg Dubicki

Although @anubhava's answer is correct, it points to the sources only and compiling it without help is hard.

尽管@anubhava 的回答是正确的,但它仅指向来源并且在没有帮助的情况下编译它很困难。

To install sshpasson MacOS using breweasily please use this unofficial package:

sshpass在 MacOS 上brew轻松安装,请使用此非官方软件包:

brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb

Source: https://gist.github.com/arunoda/7790979

来源:https: //gist.github.com/arunoda/7790979