RSS Feed

How to use ftp in shell script

May 16 2011 Published by admin under Shell Script

  • Sharebar

There are two ways I found to use the ftp commands in shell script. One is using curl and other is normal ftp session.

Using curl:

curl ftp://username:password@ftp.yourdomain.com/folderifany/filename.ext > localfilename.ext

The above command will copy the file from ftp location to local directory. It will work by simply adding the above command to the shell script. This outputs the activity to the console though so you will have to take care of that.

Using normal FTP session:

ftp  -u ftp.yourdomain.com << END_SCRIPT
user username password
cd folderifany
get filename.ext
bye
END_SCRIPT

I googled around and found the above command using -n which was not working for me so i used -u and it worked! And this does not write any activity on the console.

You can use any normal ftp command inside the ftp session like ls, put etc and they will work as they do on command prompt.

2 responses so far

  • charan says:

    I am trying to automate FTP from shell script. but I am getting error its not connecting with user name and password. please suggest an alternative

  • Hollie says:

    I enjoy this site its a master peace ! Glad I observed this on google .

Leave a Reply