1823077 Members
3411 Online
109645 Solutions
New Discussion юеВ

Replace .netrc file

 
SOLVED
Go to solution
Dewa Negara_4
Regular Advisor

Replace .netrc file

Hi All,

I have a FTP script that is using .netrc file. I do not want to use .netrc file anymore because of security reasons and want to replace the FTP script with using sftp or scp since the boxes have been installed SSH. Below is the .netrc file and FTP command taken from the FTP script.

[root@SERV_01:/home/ARPSIOA]
# more .netrc
machine SERV_02
login aigposda
password aigpos01
macdef filetransfer
cd $1
bin
put $2
chmod 644 $2
put $3
chmod 644 $3
quit

FTP command taken from the script :
echo "\$ filetransfer ${GPOS_IN_DIR} 793_oc_${TIME_ST}.stop 793_od_${TIME_ST}.stop " | ftp ${GPOS_SER_NM}

Pls Note that FTP command above is using some variabels.

What kind of sftp or scp commands can I use to replace the FTP command above? Can we use sftp or scp command with some varibles as well?

Please help. High score will be given.

Thanks alot in advance.

Best Regards,
Dewa
Santos
3 REPLIES 3
Rajeev  Shukla
Honored Contributor
Solution

Re: Replace .netrc file

If you use scp which is very simple and easy to configure. Also since it uses encrypted channel its more secure and if you use it with the certificate keys you dont need to provide the password.
Here is how it works...
On the client machine, generate the public keys using ssh-keygen command and once you have the public key with the extension .pub copy that to the server (remote host running sshd) in the home directory of the user create a file called authorized_keys in ~user/.ssh directory and put the content of the .pub file in it.
By and change the mode of the file to 600.
By doing this you can test by loging in using ssh , it wont ask for the password.
And its now you can write a script to scp your files without the worry of password.
Muthukumar_5
Honored Contributor

Re: Replace .netrc file

For scp and sftp you have to setup key sharing between machines or use expect scripting to do it easily.

You can use variable substition in sftp and scp also. All utility will be coming under SHELL. If you make shell variables then it will be applicable to the present shell globally.

You can try it as,

REM_USER="root"
REM_HOST="remote"
REM_LOCATION="/tmp"
LOCAL_LOC="/tmp/test"

scp ${REM_USER}@${REM_HOST}:${REM_LOCATION} ${LOCAL_LOC}

hth.
Easy to suggest when don't know about the problem!
Dewa Negara_4
Regular Advisor

Re: Replace .netrc file

Hi All,

Got it. Thanks alot for your help.

Best Regards,
Dewa

Santos