Automated FTP without plaintext user/password in script

hi , i am a still beginner in unix and specially in ftp i've written this script but my admin asked me that he don't want to see in my ftp neither user neither password , so i've created .netrc file where in it i've put machine name , user and pass but still included in my script , so if someone can see it to tell me who to remove my user and pass from the script to use it wthout them just automate it

the script is :

cd /tmp/FCDR_TEST
i=1
while [ $i -le 10 ]
do
  touch file$i
  i=`expr $i + 1`
done
HOST='x.y.z.u'
USER='user'
PASSWD='jajaja'
 
/usr/bin/ftp -i -n $HOST << EOF
quote USER $USER
quote PASS $PASSWD
cd /tmp/FCDR_TEST
lcd /export/home/user/tmp
mget file*
bye
EOF
rm /tmp/FCDR_TEST/file*

use sftp ( need password less ssh setup -- google it or search in this forum )

can u please just explain little bit more who to use it ???

Google Search Results for sftp password less | The UNIX and Linux Forums

thanks a lot , n i will try to find an escape

---------- Post updated at 12:45 PM ---------- Previous update was at 12:10 PM ----------

at my work we're not using yet SFTP , still of ftp so the problem can be resolved or ... ? hope not taking lot of ur time itkamaraj

is your .netrc file having the permission 600 ?

Unix -> .netrc

---------- Post updated at 01:31 PM ---------- Previous update was at 01:30 PM ----------

Google Search Results for .netrc | The UNIX and Linux Forums

yes n in it i've put machine x.x.x.x
login user
password xxxx

can you post your latest script

r u trying to tell me to use macdef in my .netrc file ? or another way if that so can u please show me how to , tx itkamaraj

---------- Post updated at 01:08 PM ---------- Previous update was at 01:07 PM ----------

1  cd /tmp/FCDR_TEST
     2  i=1
     3  while [ $i -le 10 ]
     4  do
     5  touch file$i
     6  i=`expr $i + 1`
     7  done
     8
     9  #HOST='1.1.1.1'    
    10  #USER='sfrangie'
    11  #PASSWD='sdsd'
    12
    13  /usr/bin/ftp -i -n $HOST << EOF
    14  #quote USER $USER
    15  #quote PASS $PASSWD
    16  cd /tmp/FCDR_TEST
    17  lcd /export/home/sfrangie/tmp
    18  mget file*
    19  bye
    20  EOF
    21  rm /tmp/FCDR_TEST/file*

---------- Post updated at 01:09 PM ---------- Previous update was at 01:08 PM ----------

of course the # in front of HOST n USER n pass is removed :slight_smile:

is .netrc script is under the home directory of the script owner ?

From the command prompt, just try

 
ftp $HOST

yes it is under the same home directory , which is me , n when ftp $HOST it showed me ftp> but anything typed is to be said not connected , all what i want to know is how to automoate my scripts without putting in it the user name and the password :S

For future reference:

  • Please use a descriptive subject text when posting questions, so that users with similar problems can find the thread more easily
  • Please write in complete English instead of texting slang. There's enough space for a post to include complete words like "are", "you", or "and"
  • Finally, when posting scripts, command lines, ... use [CODE] tags to enhance readability and preserve formatting.

can you put the hostname,username, password in this order in .netrc file and give a try

machine fullmachine-name login loginID password passwd

so u are telling me to remove the password and user name from my scripts and just putting them in .netrc with chmod to 600 and try my scripts , if that my script will become

Code:

     1  cd /tmp/FCDR_TEST     2  i=1     3  while [ $i -le 10 ]     4  do     5  touch file$i     6  i=`expr $i + 1`     7  done     8     9          10      11      12    13  /usr/bin/ftp -i -n $HOST << EOF    14  cd /tmp/FCDR_TEST    15  lcd /export/home/sfrangie/tmp    16  mget file*    17  bye    18  EOF    19  rm /tmp/FCDR_TEST/file* 

and the .netrc file is : machine x.x.x.x login sfrangie password sarkis1sa_Z2

if that it is giving me as response :
Not connected.
Local directory now /export/home/sfrangie/tmp
Not connected.

---------- Post updated at 01:44 PM ---------- Previous update was at 01:43 PM ----------

so u are telling me to remove the password and user name from my scripts and just putting them in .netrc with chmod to 600 and try my scripts , if that my script will become

cd /tmp/FCDR_TEST
i=1
while [ $i -le 10 ]
do
touch file$i
i=`expr $i + 1`
done

/usr/bin/ftp -i -n $HOST << EOF
cd /tmp/FCDR_TEST
lcd /export/home/sfrangie/tmp
mget file*
bye
EOF
rm /tmp/FCDR_TEST/file*

it is giving me not connected

local directory now /export/home/sfrangie/tmp
Not connected.

1) your .netrc should be under the home directory of the user (who owns the script)
2) your .netrc file should be like below.

$ cat .netrc
machine abcd.eft.com login username password xyz

3) it should have 600 permission

4) once above steps are taken care. try the below command in the command prompt and check whether it works or not

 
ftp abcd.eft.com

it worked :d , as ftp machinename ,,
my question is how to include this ftp in my script without mentioning the user and the password in the script so it would be like :

cd /tmp/FCDR_TEST
i=1
while [ $i -le 10 ]
do
touch file$i
i=`expr $i + 1`
done
HOST='x.x.x.x'
 
/usr/bin/ftp -i -n $HOST
cd /tmp/FCDR_TEST
lcd /export/home/sfrangie/tmp
mget file*
bye
EOF
rm /tmp/FCDR_TEST/file*

it is giving me now an answer :

Please login with USER and PASS.
Local directory now /export/home/sfrangie/tmp
Please login with USER and PASS.
Please login with USER and PASS.

where is your <<EOF ?

Please use the [CODE] tags

cd /tmp/FCDR_TEST
i=1
while [ $i -le 10 ]
do
touch file$i
i=`expr $i + 1`
done
HOST='x.x.x.x'

/usr/bin/ftp -i -n $HOST << EOF
cd /tmp/FCDR_TEST
lcd /export/home/sfrangie/tmp
mget file*
bye
EOF
rm /tmp/FCDR_TEST/file*

the answer for my scripts is
Please login with USER and PASS.
Local directory now /export/home/sfrangie/tmp
Please login with USER and PASS.
Please login with USER and PASS.

so how will i include my .netrc so the ftp command in my script will read the username and the password withput putting them in my script

cd /tmp/FCDR_TEST
i=1
while [ $i -le 10 ]
do
touch file$i
i=`expr $i + 1`
done
HOST='x.x.x.x'

/usr/bin/ftp -i $HOST <<-EOF
cd /tmp/FCDR_TEST
lcd /export/home/sfrangie/tmp
mget file*
bye
EOF
rm /tmp/FCDR_TEST/file*

big thanks itkamaraj :smiley: now i shall call u my adm :stuck_out_tongue: really was it from that little option -n , tx a lot again hope didn't make u tired withe me :slight_smile: