Upload File via Post Windows Command Line
How to use the curl command for uploading and downloading files without user interaction
If y'all're considering writing a script that requires downloading (or uploading) files over a network, 1 of your all-time friends volition exist the curl command.
The scroll command is quite useful and flexible. The intent of the tool is to transfer data, without user interaction, to or from a server, using one of the many supported protocols. Information technology is that list of protocols that helps whorl manage to exist so flexible, as the control 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 salubrious list of possibilities. It also means curl can transfer merely virtually 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 testify you how to make use of this command (one you'll frequently find in Linux howtos and scripts). I'll exist demonstrating on Elementary Os, but the control works on nearly every available Linux distribution. Curl is also available on macOS and Windows.
SEE: twenty quick tips to make Linux networking easier (complimentary PDF) (TechRepublic)
Installing ringlet
Your Linux distribution should have curl installed past default. If not, the installation is quite simple. On a Debian derivative, the installation command would be:
sudo apt install curl
You can cheque the installation by issuing the command curl –version. You should come across the version number of the installed awarding (on my Uncomplicated Os machine, it's vii.47.0).
Using curl
Let's commencement see how curl can be used at its simplest. Say you want to view the source of a web site. We'll use the gyre site as an example. Upshot the command:
roll https://curl.haxx.se | less
Y'all can now scroll through the HTML for that site (Effigy A).
Figure A
This is a great way to figure out how a site has been created or even troubleshooting your own sites.
Of course, that example is quite express. Let's use curlicue to pull down a file from a site. Let's stick with the aforementioned instance. Say you lot want to download the HTML for the curlicue site to view later. For this, nosotros'll use the -o switch similar so:
curl https://curl.haxx.se -o roll.html
The higher up control would download the HTML code from the scroll site and save it as coil.html. Of course, curl isn't merely capable of downloading source HTML. Say you have a file you desire to download from a site. Gyre can handle this like so:
curl http://SERVER_ADDRESS/FILENAME -o FILENAME
Where SERVER_ADDRESS is the URL of the server and FILENAME is the name of the file to exist downloaded. Say for example, yous desire to download the latest release of Ubuntu Server. That tin exist done similar so:
curl http://releases.ubuntu.com/xviii.04/ubuntu-18.04-live-server-amd64.iso -o ubuntu-server-18.04.iso
If that file is password protected, curl tin handle that like and so:
curl -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 exist downloaded.
- SERVER_ADDRESS is the direct link to the file.
You tin can also use curl with an FTP server. Say you need to download a file from an FTP server that happens to be password protected. The control 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 name of the file to be 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 again 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 password for the user on the FTP server.
At some point, the curl developers removed SFTP support from the libcurl. If you need to download a file, via SSH, yous'll need to utilize the sftp control.
Why utilize curl
One of the biggest benefits of curl is that it tin exist used without interaction. Because of that, it's perfectly suited for scripting. You'll run into many instances of Linux installer scripts that make use of curl. As an installer script runs, you might well see curl do its thing by downloading necessary dependencies. And so if you're writing a Linux bash (or installer) script, curl will most certainly be your friend. For more information on coil (and at that place'southward a lot of it), event the command man curl and read through the manual page.
Learn more about Linux in TechRepublic Academy!
Likewise come across:
- How to apply the Linux lookout command for easier output tracking (TechRepublic)
- How to use the Linux screen control to proceed your remote processes running (TechRepublic)
- How to set up an SFTP server on Linux (TechRepublic)
- How to monitor a Linux log file in real time (TechRepublic)
- ICANN makes last minute 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/
Post a Comment for "Upload File via Post Windows Command Line"