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 specified remote system
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
What about wildcards or multiple files?
scp file1 file2 more-files* user@remote:/some/dir/
This will work:
#!/usr/bin/expect -f
spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no file1 file2 file3 user@host:/path/
expect "password:"
send "xyz123\r"
expect "*\r"
expect "\r"
interact
Try lftp
lftp -u $user,$pass sftp://$host << --EOF--
cd $directory
put $srcfile
quit
--EOF--
#!/usr/bin/expect -f
# connect via scp
spawn scp "user@example.com:/home/santhosh/file.dmp" /u01/dumps/file.dmp
#######################
expect {
-re ".*es.*o.*" {
exp_send "yes\r"
exp_continue
}
-re ".*sword.*" {
exp_send "PASSWORD\r"
}
}
interact
http://blogs.oracle.com/SanthoshK/entry/automate_linux_scp_command
here's bash code for SCP with a .pem key file. Just save it to a script.sh file then run with 'sh script.sh'
Enjoy
#!/bin/bash
#Error function
function die(){
echo "$1"
exit 1
}
Host=ec2-53-298-45-63.us-west-1.compute.amazonaws.com
User=ubuntu
#Directory at sent destination
SendDirectory=scp
#File to send at host
FileName=filetosend.txt
#Key file
Key=MyKeyFile.pem
echo "Aperture in Process...";
#The code that will send your file scp
scp -i $Key $FileName $User@$Host:$SendDirectory || \
die "@@@@@@@Houston we have problem"
echo "########Aperture Complete#########";