The curl command, part of the package that comes standard with most *nix-based operating systems, allows users to transfer files from one server to another server without user interaction. This can be useful if you have automated backups running, or if you have set up an automatic data dump from your database, and so on. The syntax for using the curl command to transfer files is quite straightforward, as shown below.
What is curl?
Curl is a versatile command line utility that can be used for many different purposes, such as checking your mail, transferring file or executing arbitrary shell commands. It supports various types of authentication such as GSS-API (Kerberos), SPNEGO and NTLM.
Curl transfers data with integrity checking and different content-encoding methods. Files can be transferred in their entirety or selected portions retrieved with regular expressions or by specifying offsets into a file, ranges which can overlap or not; curl will automatically resume partial downloads where possible.
How do I use it?
You can do this by transferring a file from your computer (local machine) to a remote server (e.g. server):
- curl -T filename http://server/file_name_here
- And to download a file from the remote server, it’s just as easy:
Example uses in Linux
Files can be transferred and uploaded without interacting with a computer by utilizing the curl command. Curl is an application that has many uses in Linux environments, including transferring and uploading files. Curl is installed on most Linux systems, but can also be installed if it’s not present. To install, type yum install curl or apt-get install curl (depending on your system).
Next, you want to create a one-liner script for your favorite text editor. This script will use the curl utility and then upload or download a file from another server specified by URL.
Example uses in Windows
One way to use the curl command is on Windows by opening PowerShell and typing in: Get-Content C:\users\username\foldername\filename.ext. The file’s contents will now be displayed in PowerShell as they would be opened in any other text editing software program.
From there, press Ctrl+C, close out of PowerShell and open an up-to-date text editor program like Wordpad or Notepad. Paste the copied content from earlier into your desired document and save it as filename2.ext from within the same folder that you copied it into before.
In most cases, if you can access a file on your system, you should be able to use the curl command. You might also want to use this tool in cases where you have restricted user permissions. For example, if you’re working from home and only have limited rights on your computer’s shared file system, then you might need a little help getting that file that’s just outside of your reach. But be careful!
If someone does happen to come along and access your computer while it’s transferring a file (or files), they’ll also be able to see everything that you’ve been doing so far.
If you know how long a certain task is going to take, it can also help with estimation when utilizing these two tools together.
Transfer Files without user interaction
The following example will upload a file called text.txt to the /tmp directory with linux users permissions set as 0600 and execute it with full sudo permissions:
curl -T text.txt https://myip:port/wlsadmin/text.txt?linuxaccess=0;sudoaccess=0&os_version=2
The following example will download a file called code.bin to your current working directory with windows users permissions set as 0x30000200, execute it in full compatibility mode, and also give you a success status message:
curl -o code.bin https://myip:port/wlsadmin/code.bin?windowsaccess=03000200;fullcompatmode;successstatusmessage=true