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"
Linell
  • 750
  • 3
  • 9
  • 27

1 Answers1

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.

James Anderson
  • 27,109
  • 7
  • 50
  • 78
  • 1
    '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 http://www.samba.org/ftp/rsync/rsync.html. – u-punkt Dec 02 '11 at 07:24