shell scipt to get a file from ftp server

2019-08-31 02:44发布

问题:

I have a shell script which downloads a file from remote server. Though I am providing username and password still it is asking for pass in command prompt.

I have tried to hardcode the username and password but still it's asking for password in runtime

for host in $hosts
do
   ftp  $ftpop $host << ! > $TMPFILE.ftp 2>&1
      username
      password
      get $dataset $filename
!
  egrep '^421 |^425 |^426 |^450 |^451 |^452 |^530 |^531 |^550 |^551 |^552|^553 |^590 |^Not connected' $TMPFILE.ftp > /dev/null 2>&1
   rtn=$?
   if [ $rtn -eq 1 ] ; then 
      break
   fi
done

I expect to take the username and password and download the file.

回答1:

The typical ftp which is found in Linux honours the file ~/.netrc, into which you can store user id, password and other useful macros (https://linux.die.net/man/5/netrc). The location of this file can be specified explicitly by setting the environment variable NETRC. This can be useful if you get userid and password from some other configuration file and need tor create a suitable netrc file on the fly.



标签: shell