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
This has been answered before in the forums here.
If you don't want to specify a password you need to generate a passwordless key with ssh-keygen and then copy the public key to the target host's ~/.ssh/authorized_keys file. This also has been discussed here before. Try a search.
Thank you so much dangral. I looked at your reply and looked at the sites you suggested. I am still at a loss. It asks me to use ssh. I tried that and created a public key file. Now it asks me for passphrase for public key file. I do not want any interactive mode at all. I somehow want it to automatically take the password for a file or something. I tried the following:
The file "passwordfile" has passowrd stored in it. Still, it does not work. It first asks me for password interactively and only after I typed the password, it will execute the "passwordfile".
I looked on help for sftp and I was told that if I use non-interactive authentication, only then the above statement will work, meaning, it will take password for the batch file.
My question now is that: how do I achieve non-interactive authentication?
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:
Quote:
However, it's nice to keep everything together in one file using "here documents." What you can do, is this:
Most modern Unix flavors provide a way to access the current process' standard streams via the filesystem. Linux has /dev/stdin; under Solaris, it would be /dev/fd/0 - yours may be different.
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:
Last edited by dangral; 04-01-2005 at 01:00 PM..
Reason: added security warning
Thanks again. Unfortunately, the command ssh-keygen does not work on my machine. It gives me the error:
ssh-keygen not found.
I guess I need to call my system admin and maybe get something installed, right???
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:
Hi,
When I tried to use the snippet of your code, I am unable to connect. the -b option used by you is not viable in solaris. here it stands for buffersize.
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)