HowTo Curl Examples

From NST Wiki
Jump to navigationJump to search


cURL is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction. This page will provide practical examples using cURL with the NST distribution.

Curl Upload Examples

Uploading A File To A NST System (Post)

The NST WUI provides a page which can be used to upload files from a browser to the NST system. This upload is done by filling in form fields which is submitted via a POST using multipart/form-data. This form has the following fields:

The file to upload from the client system.
Where the file uploaded file should be installed on the NST system.
The user which should own the file after upload.
The group which the file should belong to.
The mode bit settings (like: 600) that should be applied to the file.

Normally, you interact with the /nstwui/php/system/upload.php page using your browser to fill in and submit this information. However, it is also possible to automate this process by using the curl command. This is often useful for cron jobs or creating custom scripts.

The following demonstrates

curl --netrc --insecure --form "upload_src=@/etc/hosts;filename=hosts.txt" "${URL}";

The above command requires a authentication entry in your ~/.netrc file of the form:

machine HOST login USER password PASSWORD

For example, if logging in as root on a machine with the IP address of with a password of nst2003, you would add a line like:

machine login root password nst2003

This strategy should work for any web page which accepts files via multipart/form-data forms. Obviously, you will need to inspect the HTML to see what fields the form requires for the site you want to upload as other sites will use other variable names, but the approach should be the same.

Trace Options

Add the following parameters for trace operation:

 curl --trace-ascii "/tmp/curl_session.txt" --trace-time \
   --netrc --insecure --form "upload_src=@/etc/hosts;filename=hosts.txt" "${URL}";

Tutorial References