views:

2849

answers:

4

Hello,

I have some n number of files in a directory on my unix system . Is there a way to write a shellscript that will transfer all those files via scp to a remote system, i specify . Ill specify the password within the script, so that i dont have to enter it for each file. Is there a way to do this ?

Thank You

+1  A: 

What about wildcards or multiple files?

scp file1 file2 more-files* user@remote:/some/dir/
+3  A: 

you could also use rsync. It seems to work better for multiple files than scp IMHO.

rsync -avzh /path/to/dir/ user@remote:/path/to/remote/dir/

Update

You can use rsync via ssh by adding the '-e' switch:

rsync -avzh -e ssh /path/do/dir/ user@remote:/path/to/remote/dir/
The nice thing about scp ist that it uses a secure channel. rsync does not.
You can force rsync to use ssh: 'rsync -avz -e ssh remoteuser@remotehost:/remote/dir /this/dir/'
flokra
@flokra. Thanks, I was right in the middle of adding that update and got distracted.
+1  A: 

You can do it with ssh public/private keys only. Or use putty in which you can set the password. scp doesn't support giving password in command line.

You can find the instructions for public/private keys here: http://www.softpanorama.org/Net/Application_layer/SSH/scp.shtml

Vereb
A: 
#!/usr/bin/expect -f
spawn scp -r BASE.zip [email protected]:/tmp
expect "password:"
send "wifinetworks\r"
expect "*\r"
expect "\r"
Abhinav Gupta
Can expect be used for rsync? I am trying to do something and my RSA key method is not working. It keeps asking me the password for the remote machine.
AJ