Home Linux Community Community Blogs Personal FTP file transfer with an automated bash script

FTP file transfer with an automated bash script

This is a really quick blog post, I don't wanna bother you with a complete article related to FTP, this morning I've had to automate a batch job, this job needs to transfer local data to a remote FTP server here's what I've done:


ftp -n -v $HOST << EOT
cd upload
ls -la

The script automatically connects to a remote server "" with a defined username/password pair (remoteusername, remotepasswd) and execute some commands in the middle, in my case :

cd upload
ls -la

but of course you can customize with your own commands

This is not a tech article and not even something cool, just useful as a quick tip for a newbie, hope it helps..





Subscribe to Comments Feed
  • Kalpana Said:

    Thanks for the script. Its simple and easy to use

  • Ken Diebel Said:

    Hello all, I have my user name and passsword for an FTP site that I want to access for information that is available to me to use from an FTP site .My goal is to access the FTP site at different times throughout the day and get specific tiime specific information and then pull it off the FTP site and store it at a specific location on my automation system and then play it back at specified times that I program on my automation system. Any help is appreciated.. Thank you.

  • Benjamin Said:

    I was trying to do this exact thing, and it's the -n flag that was missing. Thanks for this!

  • Rani Said:

    This works like a gem. Thank you. I'm very happy to have found this article. Works Perfectly. Thanks once again for the wonderful and handy solution.

  • m Said:

    is it possible to transfer file without username and password??

  • Daniel Said:

    Actually you can create a .netrc file in your home directory containing all login credentials so you won't need to login when you connect to that server, making scripting easier. So in you case your .netrc file would contain following line: machine login remoteusername password remotepasswd Then in your script you can just do ftp and you will not need to login with the USER command anymore! yeah! magic! :) You can have several lines in your .netrc for all your hosts

  • karthik Said:

    HI Guyz , Thanks for the script . I need to know status of the file transfer , based on which i can archive the FTPed files. I tried $? , but it returns me the status ftp connectivity and not the status of the file transfer.

Upcoming Linux Foundation Courses

  1. LFS201 Essentials of System Administration
    12 Jan » 30 Mar - Online Self-Paced
  2. LFD320 Linux Kernel Internals and Debugging
    13 Jul » 17 Jul - North Reading - MA + Virtual (GUARANTEED TO RUN)
  3. LFS426 Linux Performance Tuning
    13 Jul » 16 Jul - Virtual (Guaranteed to Run)

View All Upcoming Courses

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board