4

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.

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

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

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.

Community
  • 1
  • 1
Tiit Remmel
  • 230
  • 1
  • 5
  • 16

4 Answers4

3

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

brew install lftp
the
  • 21,007
  • 11
  • 68
  • 101
3

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

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

Greg Dubicki
  • 5,983
  • 3
  • 55
  • 68
anubhava
  • 761,203
  • 64
  • 569
  • 643
1

And for installing the latest version of sshpass using homebrew:

brew install https://raw.githubusercontent.com/EasyG0ing1/sshpassBrew/main/Formula/sshpass.rb

You might have to do this to install it:

wget https://raw.githubusercontent.com/EasyG0ing1/sshpassBrew/main/Formula/sshpass.rb

brew install sshpass.rb
Michael Sims
  • 2,360
  • 1
  • 16
  • 29
0

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

To install sshpass on MacOS using brew easily please use this unofficial package:

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

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

Greg Dubicki
  • 5,983
  • 3
  • 55
  • 68