1834045 Members
2338 Online
110063 Solutions
New Discussion

Re: regarding SFTP

 
SOLVED
Go to solution
Sachin_29
Advisor

regarding SFTP

Hi:
I am trying to SFTP some files thru Ksh I want to run the script(see below) thru scheduler. If I run this script it prompts for the password, Is there any way that it could be automated or read thru some file.
I know we could do it in FTP but FTP is not an option .. i HAVE to use SFTP
Please let me know if there is any way
#!/usr/bin/ksh
$INFILE="Input.txt"
while read -r i
do
cd /home/$i/logs
/usr/bin/sftp user@host <>output.log
put *.log
quit
EOF
done<$INFILE
Thanks

10 REPLIES 10
Simon Hargrave
Honored Contributor
Solution

Re: regarding SFTP

The "best" way to do this is setup a key pair and use ssh-agent to cache the credentials.

The next best way is to set up a key pair, with a blank passphrase. This is still secure data transfer, but if the keys are compromised, so is access.

The poorest way is to use an "expect" script. You can get expect from the HP porting center.

Regards, Simon
Sachin_29
Advisor

Re: regarding SFTP

Simon,
Thanks for the response.
I have couple of questions,
How could i do that if I have to SFTP files from 6 different server to one single server??
How is SCP ? Is it different from SFTP?
Is that an option ?
Appreciate your feedback
RAC_1
Honored Contributor

Re: regarding SFTP

You can use scp/sftp.

You need to authentication to exchange of public/private keys.

Generate the keys. ssh-keygen -t dsa
It will create the public and private keys. (*.pub) is pubic key.

Put this key in server_where_you_want_to_sftp/scp:$HOME/.ssh/authorized_keys.

Do not do cut/paste business to copy the key to authorized_keys file. Transfer the *.pub file by ftp/sftp/scp/rcp etc.

Once you are set for authentication to exchange of private/public keys, use your code to pull the files from all 6 servers to one server.

Anil
There is no substitute to HARDWORK
R. Sri Ram Kishore_1
Respected Contributor

Re: regarding SFTP

Hi,

For the difference between SCP and SFTP, see:
http://www.cam.ac.uk/cs/filetransfer/compare.html

HTH.

Regards,
Sri Ram
"What goes up must come down. Ask any system administrator."
Steven E. Protter
Exalted Contributor

Re: regarding SFTP

scp is the way to go.

scp is the rcp replacement that is secure, it is part of openssh.

Here is how you script it

$LOGDIR=/home$i/logs
cd $LOGDIR
scp *.log user@hostname://directory

You can do this password free if you follow the document I am giving you to exchange publickeys between the two servers.

You can use cat, the doc says use X but you can do it all with cat commands.

see doc

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Sachin_29
Advisor

Re: regarding SFTP

Hi :
thanks it works between my test server for me here..
But the remote server I have access to doesnt have my $HOME directory.
I could put the authorized_key files in one of the folder ? In this case how does this work??
Please let me know
Abdul Rahiman
Esteemed Contributor

Re: regarding SFTP

Sachin,
You don't have a home directory in the remote server for the login name?
Is it for only to do the sftp or something?

I think if the remote server is running ssh1, it expects the key files to be in the ~/.ssh directory.

But if it is ssh2, thre is a parameter called "UserConfigDirectory", which need to be setup in their sshd_config file. But the catch is this is a system wide parameter and all user's authorized keys file location would change.

Here is the excerpts from a ssh documentation,
5.4.1.5. User SSH directory
sshd1 expects a user's SSH-related files to be found in the directory ~/.ssh. This location can't be changed by serverwide configuration. (You have to modify the source code.)

sshd2 expects user files to be in the directory ~/.ssh2 by default, but this can be changed with the UserConfigDirectory keyword. The directory name may be literal, as in:

# SSH2 only
UserConfigDirectory /usr/local/ssh/my_dir
or it may be specified with printf-like patterns, as in:

# SSH2 only
UserConfigDirectory %D/.my-ssh
The %D pattern expands to the user's home directory. So the preceding example expands to ~/.my-ssh. The following table shows the available patterns:

Here is the full link,
http://216.239.51.104/search?q=cache:AdvSrye6xRkJ:secu.zzu.edu.cn/book/NetWork/NetworkingBookshelf_2ndEd/ssh/ch05_04.htm+ssh+userconfigdirectory&hl=en

HTH,
Abdul.
No unix, no fun
RAC_1
Honored Contributor

Re: regarding SFTP

If you do not have $HOME on that particulat server, then where does it take you when you login?? Try creating .ssh in there and putting *.pub in .ssh/authorized_keys.

Don't know, if this will work or not.

Anil
There is no substitute to HARDWORK
Sachin_29
Advisor

Re: regarding SFTP

Unfortunately, there is a very limited access to the remote server. Once I log in to the remote server, I get logged on to / i have write permission on only one directory
A. I creatd .ssh/authorized_keys under A doesnt help.. and also authorized_keys under A (just for the heck of it) ..
Truly appreciate all of your help.. learnt a lot from this thread.
Any solution is always welcome .. If i find any solution I would post it ..Last optionis to try expect which I would try to avoid..
thanks a lot..
Sachin
Jon A. Miller
Occasional Advisor

Re: regarding SFTP

May I extend the breadth of this thread:
We also are implementing SFTP; our problem is
converting our customers from the GUI WS_FTP
that I believe uses anonymous ftp, to WINSCP
GUI. Problem is preventing the customer from transversing up the directory. We have read the numerous 'chroot jail' solutions, but it seems so 'messy'. We have a common
directory for all customers who can transverse many different subdirectories. Permissions is not a viable alternative.
We are soliciting comments/best practices /solutions.
Thank you in advance