Search…
Custom FTP commands
The FTP protocol offers a wide variety of differerent commands that allow the client to perform actions, other than the plain file transfers that curl is focused on.
A curl user can pass on such extra (custom) commands to the server as a step in the file transfer sequence. curl even offers to have those commands run at different points in the process.

Quote

In the old days the standard old ftp client had a command called quote. It was used to send commands verbatim to the server. curl uses the same name for virtually the same functionality: send the specified command verbatim to the server. Actually one or more commands. -Q or --quote.
To know what commands that are available and possible to send to a server, you need to know a little about the FTP protocol, and possibly read up a bit on RFC 959 on the details.
To send a simple NOOP to the server (which does nothing!) before the transfer starts, provide it to curl like this:
1
curl -Q NOOP ftp://example.com/file
Copied!
To instead send the same command immediately after the transfer, prefix the FTP command with a dash:
1
curl -Q -NOOP ftp://example.com/file
Copied!
The third "position in time" that curl offers to send the commands, is after curl has changed the working directory, just before the commands that kick off the transfer are sent. To send command then, prefix the command with a '+' (plus).

A series of commmands

You can in fact send commands in all three different times by using multiple -Q on the command line. You can also send multiple commands in the same position by using more -Q options.
By default, if any of the given commands returns an error from the server, curl will stop its operations, abort the transfer (if it happens before transfer has started) and not send any more of the custom commands.
Example, rename a file then do a transfer:
1
curl -Q "RNFR original" -Q "RNTO newname" ftp://example.com/newname
Copied!

Fallible commands

You can opt to send indidivual quote commands that are allowed to fail, to get an error returned from the server without causing everything to stop.
You make the command "fallible" by prefixing it with an asterisk (*). For example, send a delete (DELE) after a transfer and allow it to fail:
1
curl -Q "-*DELE file" ftp://example.com/moo
Copied!
Last modified 10d ago
Export as PDF
Copy link
Edit on GitHub