We have already seen how to connect to an FTP server and work with it (or its content) through the terminal, that is, without using graphic applications.
This time I bring you a plus or an extra ... let me explain.
Some years ago I left them a bash script used to make backups (saves) of data from a server. The script copied a series of folders (like / etc /), exported databases, etc ... and compressed it with a password into a .RAR or .7z file (I currently use 7z), the only thing that the script lacked was to be able to upload then that compressed file to some FTP server, in this way the save from the server would be copied to another location.
These days I took up the script to optimize it a bit, improve it and obviously the need for the latter that I mentioned to you came to light, uploading the compressed archive to an external FTP.
Table of Contents
How to upload to an FTP with a single command?
What I needed was through a single command to connect to an FTP with username and password, and well; upload the file to a specific folder.
Terminal applications that allow me to connect to an FTP, put user & password and upload files there are lots of them, but… that allow me to do this all in one line, with all the parameters already specified…. hey there the question.
After reviewing 4 or 5… I thought, huh !! ... but it exists curl
Upload to an FTP with curl
With curl I can do an infinite number of things, maybe I can do what I want… and that's it!
With the -u parameter I can specify the username and password, also with the -T parameter I can tell it to upload a file, and finally to tell it to which FTP and which folder I want to upload it, at the end I just put the full path, more or less like this :
curl -u usuario:password -T archivo-backup.7z ftp://192.168.128.2/SERVER_BACKUPS/
What this does is connect to the FTP 192.168.128.2, with the user user and password Password and upload to the folder SERVER_BACKUPS the file called file-backup.7z
Simple right? ...
Of course, this can be useful to us as well the command alone, however, the best way to use it is with a script such as ... the one I mentioned before
And what about that script that is mentioned?
I am making improvements to the script, especially incorporating some requests or suggestions from users.
- The first thing I wanted to do was precisely this that I just explained to you, with a single command to upload the save file to an FTP.
- The other thing that a user recommended me was to send an email when the backup was ready, for that I can use sendmail or external script, I will preferably use sendmail. The detail of using sendmail is that you can use your GMail account (or any other) to send the email, with encryption ... SSL and whatever.
- Also, a user recommended that also, as a more dynamic form of notification, a message be sent by IM using GTalk's XMPP or Hotmail's (Live or something like that, I don't even know what it's called). I will try to do it with GTalk first, because for Hotmail I would have to remember or support myself somewhere to create a Hotmail account, because with so much change-change that Microsoft has, no idea what it is like.
- Another variant of the latter would be to use notifications or messages that are sent by Facebook or Twitter. For Twitter you could use Twidge while for Facebook you could use fbcmd. Both applications allow me to interact with these social networks from the terminal.
- I'm also thinking of checking the integrity of the sql that I export, but this already requires a little more time :)
Well, nothing more to add ... for the moment, I am taking up several of my scripts made in Bash to optimize and improve them, I hope it won't take me too long to bring news 😀