Search code examples
linuxunixscriptingftplftp

FTP specific files


Can we ftp specific files from a directory. And these specific files that needs to be transferred will be specified in config file.

Can we use a for loop once logged into ftp (in a script) for this purpose.

Will a normal ftp work when transferring files from Unix to win ftp server.

Thanks, Ravi


Solution

  • You can use straight shell. This assumes your login directory is /home/ravi Try this one time only:

      echo "machine serverB user ravi password ravipasswd" > /home/ravi/.netrc
      chmod 600 /home/ravi/.netrc
    

    test that .netrc works - ftp serverB should log you straight in.

    Shell script that reads config.file, which is just a list of files to send

    while read fname 
    do
       ftp serverB <<EOF
       get $fname
       bye
    EOF         # leave the EOF  in column #1 of the script file
    done < config.file
    

    This gets file from serverB. Change get $fname to put $fname to send files from serverA to serverB