0

I am trying to make a bash script that will transfer a file from my machine to a server maintained by my school that is used to back up code. It is a hassle to transfer the file manually every single time that I want to make the transfer.

Some applications, like TextWrangler, have the ability to save to server. However, I would rather be able to do it quickly from terminal.

Where would I go from here? Would I need to somehow pass in the file I'd like to send as a parameter? Is there a way to make sure that it goes to the correct directory?

#!/bin/bash
# This should log me into orca
# http://aruljohn.com/info/filetransfer/
# http://stackoverflow.com/questions/1895185/how-to-ssh-from-within-a-bash-script
sftp username@place
expect "username@place password: "
sleep 1
send "mypassword"
1
  • Perhaps this question would get better answers on serverfault or ubuntu. Commented Dec 2, 2011 at 4:06

1 Answer 1

2

Why not use "scp" secure copy instead of sftp.

You don't need "expect" to run this, and, if you configure the remote/local certificates properly you will not need to mess with passwords.

See some examples of how simple it can be. And the full how to docs.

Sign up to request clarification or add additional context in comments.

1 Comment

'scp' is probably sufficient for what you currently want. Should your scenario get more complex I'd recommend to have a look at 'rsync' (which can use ssh), see samba.org/ftp/rsync/rsync.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.