How to Upload and Download File in Unix
How to utilize the curl command for uploading and downloading files without user interaction
If yous're considering writing a script that requires downloading (or uploading) files over a network, 1 of your best friends will be the curl command.
The coil control is quite useful and flexible. The intent of the tool is to transfer information, without user interaction, to or from a server, using one of the many supported protocols. It is that list of protocols that helps scroll manage to be so flexible, as the command supports:
- DICT
- FILE
- FTP
- FTPS
- GOPHER
- HTTP
- HTTPS
- IMAP
- IMAPS
- LDAP
- LDAPS
- POP3
- POP3S
- RTMP
- RTSP
- SCP
- SMB
- SMBS
- SMTP
- SMTPS
- TELNET
- TFTP
That's a good for you listing of possibilities. It likewise means curl can transfer simply nigh any type of data. Curl can even display the source code of a URL. All of this without requiring user interaction (a crucial feature for scripting).
I want to show you lot how to brand use of this control (one you'll frequently find in Linux howtos and scripts). I'll exist demonstrating on Simple OS, but the command works on nearly every available Linux distribution. Curl is also available on macOS and Windows.
Encounter: twenty quick tips to brand Linux networking easier (free PDF) (TechRepublic)
Installing gyre
Your Linux distribution should have curl installed past default. If not, the installation is quite simple. On a Debian derivative, the installation command would exist:
sudo apt install curl
Yous can check the installation by issuing the command ringlet –version. You should run across the version number of the installed application (on my Elementary Os automobile, it's seven.47.0).
Using curl
Let's commencement see how curl can exist used at its simplest. Say you desire to view the source of a spider web site. We'll use the curl site as an instance. Issue the command:
roll https://coil.haxx.se | less
Yous can at present whorl through the HTML for that site (Figure A).
Figure A
This is a cracking way to figure out how a site has been created or even troubleshooting your ain sites.
Of form, that instance is quite limited. Allow's use scroll to pull downwardly a file from a site. Let's stick with the aforementioned example. Say you desire to download the HTML for the curl site to view later. For this, we'll apply the -o switch like and so:
scroll https://curl.haxx.se -o curl.html
The above command would download the HTML code from the curl site and save it every bit coil.html. Of class, curlicue isn't only capable of downloading source HTML. Say you take a file you desire to download from a site. Gyre can handle this similar so:
curl http://SERVER_ADDRESS/FILENAME -o FILENAME
Where SERVER_ADDRESS is the URL of the server and FILENAME is the proper noun of the file to be downloaded. Say for instance, you want to download the latest release of Ubuntu Server. That tin can be washed like so:
curl http://releases.ubuntu.com/18.04/ubuntu-eighteen.04-alive-server-amd64.iso -o ubuntu-server-18.04.iso
If that file is password protected, coil can handle that similar and so:
scroll -u USERNAME:Password http://SERVER_ADDRESS -o FILENAME
Where:
- USERNAME is the username on the server.
- PASSWORD is the password for the user on the server.
- FILENAME is the file to be downloaded.
- SERVER_ADDRESS is the direct link to the file.
Y'all tin can as well utilize curl with an FTP server. Say you lot need to download a file from an FTP server that happens to be password protected. The command for this would be:
curl ftp://SERVER_ADDRESS/FILENAME -user USERNAME:PASSWORD -o FILENAME
Where:
- SERVER_ADDRESS is the address of the FTP server.
- FILENAME is the proper noun of the file to exist downloaded.
- USERNAME is the username on the FTP server.
- PASSWORD is the password for the user on the FTP server.
To upload a file to an FTP server, the command would be:
curl -T FILENAME SERVER_ADDRESS -user USERNAME:PASSWORD
Once more where:
- SERVER_ADDRESS is the address of the FTP server.
- FILENAME is the name of the file to be downloaded.
- USERNAME is the username on the FTP server.
- Password is the countersign for the user on the FTP server.
At some point, the curl developers removed SFTP support from the libcurl. If y'all need to download a file, via SSH, you lot'll demand to use the sftp command.
Why employ ringlet
I of the biggest benefits of curlicue is that information technology tin be used without interaction. Because of that, information technology's perfectly suited for scripting. You lot'll meet many instances of Linux installer scripts that make utilise of scroll. Equally an installer script runs, you might well come across roll do its matter by downloading necessary dependencies. And then if you're writing a Linux bash (or installer) script, curl will most certainly exist your friend. For more than information on curl (and there's a lot of information technology), issue the command human being whorl and read through the manual page.
Learn more about Linux in TechRepublic Academy!
Also see:
- How to use the Linux watch command for easier output tracking (TechRepublic)
- How to use the Linux screen command to go on your remote processes running (TechRepublic)
- How to set up an SFTP server on Linux (TechRepublic)
- How to monitor a Linux log file in existent fourth dimension (TechRepublic)
- ICANN makes last infinitesimal WHOIS changes to address GDPR requirements (ZDNet)
Source: https://www.techrepublic.com/article/how-to-use-the-curl-command-for-uploading-and-downloading-files-without-user-interaction/
Enregistrer un commentaire for "How to Upload and Download File in Unix"