Read the article that everyone's commenting on.
Subscribe to the RSS Feed for comments on this article.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I don't believe so. I vaguely recall having to enable login ability for
accounts with which I want to do this.
Leo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
iD8DBQFGFBU3CMEe9B/8oqERAtkwAJ4t3CuIMp7Ld/5D+2CElHl7TeP+qQCfXJX4
8P8DihofejdoYIYiwuWF1rQ=
=7nkv
-----END PGP SIGNATURE-----
This was a superb article. I am going to try getting it incorporated into our IT procedures. Thank you very much.
Posted by: Cowboy at April 5, 2007 7:43 AMIf you want to automate sftp because for some reason scp doesn't work in you situation you can try "expect" You need to install it. The script would look something like this:
Replace:
DIR=local and remote directories.
IP-adress=remote server address
user=user set up on remote sftp server.
#!/usr/local/bin/expect -f -d
# Expect script that automates sftp
###################################
spawn /usr/bin/sftp user@"IP-adress"
expect "user@IP-adress's password: "
sleep 7
send Password\r"
expect "sftp> "
send "lcd DIR\r"
expect "sftp> "
send "cd DIR\r"
expect "sftp> "
send "cd DIR\r"
expect "sftp> "
sleep 10
send "mput *.pgp\r"
sleep 10
expect "sftp> "
send "bye\r"
Leo, I put your steps to use and they work. Mostly.
Here's my situation:
3 servers, I'll call A, b and c.
A: RHEL4
b: Solaris 8 on Sparc
c: Solaris 8 on Sparc.
If I send from A to b or c, the automation works fine. If I send from b or c to A, I am challenged with a password request. b and c have A's public RSA key. A has both b and c's RSA public keys. In every case, I am the user who is also attempting the SCP connection. It is most expedient to auto send from b to A, but I can rewrite b's script to run on A, if I must. Just wondering why its only working in one direction.
Posted by: Andy at July 13, 2007 5:23 AMLeo, it turns out that on server A, the authorized_keys file had permission 664. Apparently if that file is writable by anyone other than the owner, you will be challenged for a password, regardless. Once I CHMODed it to 644, the process worked flawlessly.
Posted by: Andy at July 13, 2007 6:01 AMHi Leo,
I generated rsa keys for system a and b and put both keys in authorized_keys for my user on system c.
system a connects using sftp and does not prompt for a password.
system b prompts for a password - when I provide it the connection is made.
on all 3 systems all files in .ssh are writable only by the user.
what should I be looking at to trouble shoot this?
Posted by: mike huber at September 18, 2007 8:07 AMHi Leo, Thanks for the tip, great info!
Posted by: George Schweizer at October 2, 2007 2:41 PMLeo, excellent article!! But it has worked for me only when i try to ssh/sftp to root account on server machine (server2 in the ex.). Any other user (making all the steps for each one) fails.
Is there any trick related to that ??
Thanks in advance.
I am having same problem as "Manoj Das".
here is part of the post and your comment on it:
script:
sftp ncc_b2b@blrsun27
get file1.txt
exit
I have followed the steps given by you for automated connection. Once I am executing this, it's automatically connecting to the remote system and I am getting the SFTP prompt. But it's not executing the get command.
Can you please guide me how to do this now, as the -b option is not available.
Posted by: Manoj Das at October 3, 2006 07:36 AM
YOu might need to have
get file1.txt
exit
in one file (commands.txt) and then use that as input for the sftp command:
sftp
Posted by: Anju at December 5, 2007 8:48 AMThis is followup to my earlier post. I made it work sort of:
#!/bin/ksh
sftp -B commands.txt user1@pontoon
in commands.txt I have
get 1.dat 2.dat ( I want to get 1.dat and rename it to 2.dat)
quit
It gets 1.dat and complains can not find 2.dat on remote server.
Here is some other info about my system:
sftp -V
sftp: F-Secure SSH 3.1.0 (build 12) on sparc-sun-solaris2.8
thanks for reading my posts.
Posted by: Anju at December 5, 2007 11:09 AMTo post a comment on "How can I automate an SFTP transfer between two servers?", please return to that article's main page.