Friday, September 10, 2010

Linux FTP using a script

I was using ftp -s:filename on windoze machines in order to FTP files. On the other hand the "s" switch is mising on a Linux based OS. You must use the "<"  symbol to redirect input from a file. Furthermore you can implement autologin using .netrc.

  • Create a file under home named .netrc
  • populate file with server entries of the following format:
               machine myownmachine
               login myusername
               password mypassword
    e.g
               machine testserver
               login poweruser
               password 123456

  • Execute command chmod 600 .netrc so the owner and only the owner can access the file's contents. If you skip this line the autologin feature is going to fail.
  • create a file with the ftp commands you want to execute
  • You can now execute ftp testserver < commandfile
  • Enjoy

3 comments: