automate sftp using unix script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting automate sftp using unix script
# 8  
Old 04-21-2005
Thanks Dangral
# 9  
Old 06-15-2005
Quote:
Originally Posted by dangral
I think you have two issues here:

1) Achieving passwordless authentication
2) automating sftp

I will try to discuss one at a time. Forgetting about sftp for a second, in order to achieve passwordless authentication ( in your terms non-interactive authentication) you need to set up a key that does not have a password. See this link for tips on how to set that up.

However, please see this warning and tips on how to set it up to be secure. (Sorry for all the links)

Once you have verified passwordless authetication is working, you can now attempt to automate sftp. What the link in my previous post said is:


You would not be putting a password file after sftp -b, you would be putting your standard-in device or a file with all the ftp commands. So on solaris, your script might look like this:

Code:
  
  #!/bin/sh
  echo "OK, starting now..."
  sftp -b /dev/fd/0 remotehost <<EOF
  cd pub
  ascii
  get filename.txt
  bye
  EOF

the link you have given does not work, tried the steps on solaris 9 and it still asks for password....
# 10  
Old 06-15-2005
Well if you can get the user keys working that will make things much easier.

Also, why don't you just use scp instead? Or maybe curl?

Something like this...
Code:
#!/bin/sh

scp remoteuser@remotehost:/path/to/file.txt /path/to/local/target

With the user keys setup you wouldn't have to interact with it at all- but remember it's a lot harder to get a password from my head than from my .ssh folder...

Last edited by STiVo; 06-15-2005 at 04:25 PM..
# 11  
Old 07-29-2005
use expect

using expect can get around the password verification issue.

Code:
/usr/local/bin/expect <<EOF
spawn  /usr/local/bin/sftp user@remotehost
expect "password:"
send "cd pub \r"
expect "sftp> "
send "ascii \r"
expect "sftp> "
send "get filename.txt \r"
expect "sftp> "
send "bye \r"
EOF

# 12  
Old 12-12-2005
I am looking for a script that will allow me to automate file transfer via 'sftp'. key-gen is not an option as the 'client' (where we are 'getting' the files from) will mot permit us to generate the public/provate' keys for scp.
I have tried a number of examples shown and none of them work with sftp Each one either balks at the password or prompts for the password. Can someone show me a way to do this? Thanks.
# 13  
Old 01-25-2006
Quote:
Originally Posted by priyamurthy2005
Hi All,
I need to write a UNIX script that automates the sftp process. I should be able to do a sftp to a secure box and get a file from there. I am having a problem doing this because no matter what I do, when I run my script, I get a prompt at command line asking for a password. How could I automate this? Could someone give me a sample script?
Thanks in advance.
Priya
DID YOU EVER GET THIS TO WORK??
# 14  
Old 05-08-2006
automating sftp

All,

This is a great forum for beginners like me. I have been following this thread in its multiple forms on various websites. I got a good start by following this thread but got stuck after doing exactly what has been mentioned in this thread word by word. The pain area : it was still prompting me for a password everytime.

Then, somebody suggested to recreate $HOME/.ssh directory again from scratch. Guess what, i did that and now i am able to log on from one server to another without being prompted for a password.

I dont know how much this information is gonna be useful to ppl but sure proved the definite solution for me and i thought i probably should share it with everybody.

Regards
Vikas.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sftp automate

hi, I am trying to automate a file download process using sftp. There is some logic to download files. 1) I need to login to destination server and then go to folder. 2) find list of files and count 3) using list of files I need to eliminate three selective files and download remaining... (1 Reply)
Discussion started by: getmilo
1 Replies

2. UNIX for Dummies Questions & Answers

Automate sftp process using script

Hi, guys, I am trying to automate a sftp process using "expect" method (since the key authentication method is disabled in my company network, there is no helping it). In order to try, I type in the command manually: sftp @ > << EOF >cd >ls -l >EOF >Connecting to @servername password: ... (3 Replies)
Discussion started by: warmboy610
3 Replies

3. Shell Programming and Scripting

SFTP script to automate login in to remote server

Greetings, guys. I'm not much of a programmer forgive me for being a noob, because of someone leaving, I was put in an IT spot where I have to figure out a few things. Being new to Linux and programming has been a challenge. My boss has asked me to create an automated script to connect to a 3rd... (7 Replies)
Discussion started by: giovannym
7 Replies

4. Shell Programming and Scripting

Using expect to automate sftp

I am trying to use a for loop in my expect cmdFile that I am calling. I want to be able to call either one file name or a series of file names in the working directory (that I won't know the names before hand) and then pass the names to the sftp program. Something like for i in (ls *txt) do (0 Replies)
Discussion started by: vedder191
0 Replies

5. UNIX for Dummies Questions & Answers

automate sftp in sun solaris.

Hi, I'm using Sun Solaris OS. I have configured sftp and can exchange files in command prompt. Now when I try to automate it in ksh script, facing issue as I want to capture the status if the transfer was successful or not. So tried sftp -b and sftp -B option but its not working. The... (3 Replies)
Discussion started by: shinny
3 Replies

6. Shell Programming and Scripting

Unix Shell Script to automate email alert

Hi all, I have a task on my plate which is of high priority. I need an automated email alert that checks FTP notices subdirectory on a daily basis and forwards any word files to a group of people. This word files gets created whenever there is an issue with FTP connectivity. Please help...... (1 Reply)
Discussion started by: stunnerz_84
1 Replies

7. Shell Programming and Scripting

How to automate sftp without using expect script?

How to automate sftp with out using expect script? My batch file has the password but it is not taking. Please see below. I want to use this sftp connection in a loop for pushing new files in a directory one at a time. Hence I can not use an expect script. bash-2.05$... (5 Replies)
Discussion started by: Tuxidow
5 Replies

8. Shell Programming and Scripting

How to automate sftp in a script to 'get' files.

Hi, I read a couple of forum entries about scripting sftp using the '-b' option, but in my case it still prompts for the password. Does anyone have a sample script for an sftp block to 'get' files from the remote server without prompting for a password? Both the remote and the local servers... (1 Reply)
Discussion started by: ChicagoBlues
1 Replies

9. AIX

Automate SFTP UNIX to Windows

Hi, Could you please help to solve the below issue... my requirement is automate the SFTP between UNIX and Windows server. I want to get and put some files to UNIX AIX machine(SFTP client) to Windows server(SFTP server). For that, i have generated key pair (private/public) in my AIX machine .... (6 Replies)
Discussion started by: mahiban
6 Replies

10. Shell Programming and Scripting

Automate SFTP is not working

Hi All:cool:, i tried to automate SFTP process after passwordless authendication. Stil i am getting error... Can anyone help.... ------------------- sample code below ------------------- sftp -v $mdskk@100.4.4.75 << EOF cd /data mget *.tar.gz bye EOF... (2 Replies)
Discussion started by: senthil_seera
2 Replies
Login or Register to Ask a Question