- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: sftp script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 05:28 AM
05-06-2009 05:28 AM
I have a script as follows:
cat script1
#!/usr/local/bin/expect
spawn sftp -v root@192.168.55.242
expect "password:"
send "root123\n";
interact
This will work up to sftp prompt. I need to add three sftp command
1) cd /var
2)put star.txt
3) bye
Where I can add these three commands in above scripts?
Thanks and regards
Davis Paul
Solved! Go to Solution.
- Tags:
- sftp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 06:14 AM
05-06-2009 06:14 AM
Re: sftp script
expect "my successful login string here"
cd /var
put star.txt
bye
HTH
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 06:21 AM
05-06-2009 06:21 AM
Re: sftp script
I would setup public SSH keys and do something like I do in this thread:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1308338
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 06:25 AM
05-06-2009 06:25 AM
Re: sftp script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 06:34 AM
05-06-2009 06:34 AM
Re: sftp script
keeping the root password in script or any text file is not a secure way.
You can simply configure ssh password less login between source and destination server and write a simple script to transfer the files like below.
#--------------------------------------------
# Connect to server and put the files
#--------------------------------------------
sftp root@193.23.116.107 <<**
lcd
cd /var
put star.txt
**
Ganesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 06:35 AM
05-06-2009 06:35 AM
Re: sftp script
How to get the string?
Court Campbell,
My goal is to copy one file across the network. How can I change this one in to scp? That should not ask username and password( means automatic file transfer)
Regards
Davis Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 06:36 AM
05-06-2009 06:36 AM
Re: sftp script
Not necessarily. I have to exchange one file a day with an external vendor using their sFTP server, and they will *NOT* allow me to just scp the sucker. I had to dance the Key Exchange Dance and am forced to use sftp and ONLY sftp for the transfers. Resulting in a long-ish back-and-forth script. For ONE file. :-(
(Can you tell that having to jump thru eleventy-bazillion hoops to transfer a single file that could be sent in one easy step has me Somewhat Annoyed?)
HP-Server-Literate since 1979
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 06:39 AM
05-06-2009 06:39 AM
Re: sftp script
I cannot create a password less login . Because the destination server control is not in our hand.
Regards
Davis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 06:40 AM
05-06-2009 06:40 AM
Re: sftp script
Follow these steps to configure ssh password less login.
1.Login to serverA as user1.
2.$ssh-keygen -t dsa
Press enter for all the questions.It will create the private/public keys
under $HOME/.ssh/
File names are id_rsa and id_rsa.pub
3.Now you need to copy the id_rsa.pub file content into ServerB $HOME/.ssh/authorized_keys file
ServerA#scp ~user1/.ssh/id_rsa.pub ServerB:/tmp
Login to ServerB server
ServerB#cat /tmp/id_rsa.pub >> ~user1/.ssh/authorized_keys
Make sure the following permissions on serverB.
Home directory should have 755 permission (users home directory)
$HOME/.ssh directory should have 700 permission
$HOME/.ssh/authorized_keys file should have 600 permission
Ganesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 06:45 AM
05-06-2009 06:45 AM
Re: sftp script
Using an interactove session, not the script, login to the destination server.
watch the screen after you enter the password, and note the last line printed on the screen. That should be your expect string. My servers do not say anything upon successful login, so I can skip that expect statement if I were to use your script, but you might (or might not) need it.
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 06:50 AM
05-06-2009 06:50 AM
Re: sftp script
If you cannot have ssh password less login, and afford to use ftp instead of sftp follow the below steps.
1.Put a entry in root .netrc file like this.
#vi /.netrc
machine 192.168.55.242 login root passwd root123
2.Your script should be like this
#--------------------------------------------
# Connect to 192.168.55.242 and put the file
#--------------------------------------------
ftp <<**
open 192.168.55.242
lcd /path
cd /var
bin
put star.txt
bye
**
#--------------------------------------------
This will work. But note that this is plain transfer not like sftp which is more secure.
Ganesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 06:58 AM
05-06-2009 06:58 AM
Re: sftp script
Mel Burslan,
nothing is printed as below:
# sftp root@192.168.55.242
Connecting to 192.168.55.242...
Password:
sftp>
sftp> bye
#
Then , how to edit the script???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 07:07 AM
05-06-2009 07:07 AM
Re: sftp script
#!/usr/local/bin/expect
spawn sftp -v root@192.168.55.242
expect "password:"
send "root123\n";
interact
cd /var
put star.txt
bye
Note that you are trusting the system that it logged you in successfully. If your login has failed, unpredictable implications may occur. Hence, use it at your own risk.
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 11:19 AM
05-06-2009 11:19 AM
Re: sftp script
Thanks for the 2 cent comment, but there is a difference in a suggestion and a definitive answer. If you read carefully you would notice that I stated I did not know what DP's goal is.
And to answer your quesiton DP. Just setup a priv/pub key that has no passphrase. Then put the pub key in the aurthorized key file on the remove server. Then you could just
scp /your/file remote_server:/remote/directory
But as Mike has pointed out that mayu not work for your situation. since this is a simple one liner you could easily add it to a crontab.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 02:37 PM
05-06-2009 02:37 PM
Solution"nothing is printed as below:
# sftp root@192.168.55.242
Connecting to 192.168.55.242...
Password:
sftp> <---
sftp> bye"
No...you got "sftp>" (see "<---" above)
something like the following *might* work:
#!/usr/local/bin/expect
spawn sftp -v root@192.168.55.242
expect "password:"
send "root123\n";
expect "sftp>"
send "cd /var"
expect "sftp>"
send "put star.txt"
expect "sftp>"
send "bye"
If you've an account on the remote server, consider the public key methods described above. Or possibly contacting them to see if they can arrange to install your key for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 09:43 PM
05-06-2009 09:43 PM
Re: sftp script
Its working.
Regards
Davis Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2009 11:33 PM
05-06-2009 11:33 PM