cancel
Showing results for 
Search instead for 
Did you mean: 

SCP and SFTP Configuration

Sac77
Advisor

SCP and SFTP Configuration

I need to Configure password less SCP and SFTP for our HPUX 11.11i server which will connect to windows server and transfer the file's on a particular timming as per requirment everything need to be automated.

would anyone please let me know. thanks!
8 REPLIES
Ivan Krastev
Honored Contributor

Re: SCP and SFTP Configuration

See this tutorial - http://blogs.translucentcode.org/mick/archives/000230.html

for Windows client use Pageant and psftp from here - http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

regards,
ivan
Sac77
Advisor

Re: SCP and SFTP Configuration

Hi Ivan,

as i mentioned earlier i need to do the changes from hpux to windows...but in the link you have provided me its for two unix machine. and i am not able to understand which are the steps i need perfom on windows or linux server... as far as i understand i belive i need to genrate the key -

$ ssh-keygen -t dsa

and copy this key to windows server.
because the movement is from windows to unix.
Ganesan R
Honored Contributor

Re: SCP and SFTP Configuration

Hi,

Decide which user is going to perform the file transfer on hp-ux.

Login as that user.

Generate the public key using the following command ssh-keygen -t dsa.

Copy the id_dsa.pub file from ~/.ssh directory and save it on windows server.
Remember to change the ownership and permission as per windows sftp server requirement.

Schedule the cronjob to put the files on windows server or to get the files from windows server as per your requirement.

Hope this helps
Best wishes,

Ganesh.
Sac77
Advisor

Re: SCP and SFTP Configuration

Hi Ganesan,

Thanks for the replay, however are you aware where to save the id_dsa.pub on windows server.

Also, do you have any sample script which will put the file on windows server using both SCP and SFTP. thanks!
Ganesan R
Honored Contributor

Re: SCP and SFTP Configuration

Hi,

I am really not sure where to copy the public key on windows server and what should be the file name. If it is a unix server you need to copy/append as authorized_keys under ~/.ssh directory. You need to refer the windows sftp server manual documnet.

Here you can see the sample script which use sftp to put the file. You need to customise as per your requirment.

---------------------------------------------
LOG=/var/ftp/abc/log
TODAY=`date +'%d%b%y'`
echo "`date +'%d%b%y %T'`" >> $LOG
#-------------------------------------------------------
# Check if Any files exist for sftp transfer and convert
with ux2dos before transferring
#-------------------------------------------------------
fn=`ls /var/ftp/abc/incoming/`

if [ ${fn:-NO} = "NO" ];
then
echo "No file" >> $LOG
exit
else
echo "Files to send: $fn" >> $LOG
/usr/bin/ux2dos /var/ftp/abc/incoming/$fn > /var/ftp/abc/incoming/$fn.DOS
#-------------------------------------------------------
# Connect to "10.110.115.120" server and put the files
#-------------------------------------------------------
sftp sftpuser@10.110.115.120 <<**
lcd /var/ftp/abc/incoming
put $fn.DOS
**
#-------------------------------------------------------
# Cleanup and copy them to archive for backup
#-------------------------------------------------------
cd
mv incoming/$fn /var/ftp/abc/archive/$fn.$TODAY
compress /var/ftp/abc/archive/$fn.$TODAY
rm /var/ftp/abc/incoming/$fn.DOS
fi
-------------------------------------------------------
The above script assumes that /var/opt/abc is the home directory of unix user and you are having the files to be transferred under incoming directoy. Also you can ignore ux2dos command if you don't need that. This is necessary if you are going to read the file as dos format on windows machine.
Best wishes,

Ganesh.
Sac77
Advisor

Re: SCP and SFTP Configuration

Hey,Thanks a lot for the script however i've one more server which is need to be configure using SCP and do copy of the file on remote system. It also goes in same direction means Windows to UNIX. So, Can i perform the same changes for SCP to ?
Ganesan R
Honored Contributor

Re: SCP and SFTP Configuration

Hi,

You can use SCP instead of SFTP. You will have to modify the script as per your requirement. That's it you are done.

Make sure that passwordless authentications is working before you schedule the job.

Best wishes,

Ganesh.
rmueller58
Valued Contributor

Re: SCP and SFTP Configuration

My personal recommendation Unix to Windows would be to mount as a CIFS file system.

1. Add an entry to /etc/fstab on the Unix Box for the Microsoft server

### Syntax of FSTAB
//REALIP/MS-SHARENAME /unixmountdir cifs user,password=ms-passwd,ip=realip,username=ms-username 0 0


Then you can define a cron job that copies from one location to the 2nd..

In order to use secure copy from Unix to Microsoft you would have to define an SSHD service on your microslop box, this starts adding way to much into the equation

The CIFS mounted directory is the way to go.


My syntax for a scripted solution would be
cp -p unixdir/filename /mountpointname/directory/filename

You will need to determine the correct permission definitions to allow the CIFS mount to occur 1st. then the copy is as simple as copying from locationA to LocationB