cUrlis a terminal based client for data exchange over URL syntax.
I knew this definition about curl and I was usually using curl against
http endpoints with a several combination of options. There was a time at work where I had to troubleshoot an issue in production and logs were shared over an ftp server path. Little did I know that this little tool would just work with
ftp endpoints as well. So, here are some of the combinations I used curl to work on ftp endpoints. These are just starting points to give quick start and there are many more scenarios as well.
Straight forward. Just remember that the directory to be listed would be the home directory of the authenticated user. Output would be list of all files & directories in the home directory of the authenticated user. While trying out listing, try using
--list-only to only return the name of remote objects.
curl "ftp://<ftp-host>:21" --user <ftp-user-id>:<ftp-user-password>
-T, in short, is used to upload files.
curl --upload-file ./<local-filename> "ftp://<ftp-host>:21/<remote-filename>" --user <ftp-user-id>:<ftp-user-password>
-o (lowercase) is used to collect the content from the remote stream.
curl "ftp://<ftp-host>:21/<remote-name>" -o ./<local-filename> --user <ftp-user-id>:<ftp-user-password>
Additional point to remember is to consider
-O (uppercase) when the file has to be downloaded with the same name as in remote.
Recollect that use of
-X option used to set the method name like
GET, PUT, POST, DELETE against http endpoints. It is because http server had commands named like
DELETE. In similar lines, FTP server has a command
DELE <file-to-delete> to purge the given file.
curl "ftp://<ftp-server>:21" -X "DELE remote-file" --user <ftp-user-id>:<ftp-user-password> -v
- Use the option
-vfor debugging. There is a lot to understand out of the request and response once this debugging switch is enabled.
- FTP server I used was not over ssl. In case, the remote FTP server is over ssl, use the switch --ftp-ssl.
That's it !
But yes, there are a lot more scenarios like handling directory recursion, purging a directory, handling binary content. But then the idea is that curl works well on ftp protocols. That makes it easy to script. Then there is no need of a dedicated application for working on FTP requests/responses.