Command line FTP
FTP, the File Transfer Protocol, is probably the oldest network protocol thatcurl supports—it was created in the early 1970s. The official spec thatstill is the go-to documentation isRFC 959,from 1985, published well over a decade before the first curl release.
FTP was created in a different era of the Internet and computers and as suchit works a little bit differently than most other protocols. These differencescan often be ignored and things just works, but they are also important toknow at times when things do not run as planned.
Ping-pong
The FTP protocol is a command and response protocol; the client sends acommand and the server responds. If you use curl's-v
option you get to seeall the commands and responses during a transfer.
For an ordinary transfer, there are something like 5 to 8 commands necessaryto send and as many responses to wait for and read. Perhaps needlessly to say,if the server is in a remote location there is a lot of time waiting for theping pong to go through before the actual file transfer can be set up and getstarted. For small files, the initial commands can take longer time than theactual data transfer.
Transfer mode
When an FTP client is about to transfer data, it specifies to the server whichtransfer mode it would like the upcoming transfer to use. The two transfermodes curl supports are 'ASCII' and 'BINARY'. Ascii is for text and usuallymeans that the server sends the files with converted newlines while binarymeans sending the data unaltered and assuming the file is not text.
curl defaults to binary transfer mode for FTP, and you ask for ascii modeinstead with-B, --use-ascii
or by making sure the URL ends with;type=A
.
Authentication
FTP is one of the protocols you normally do not access without a user name andpassword. It just happens that for systems that allow anonymous FTP access youcan login with pretty much any name and password you like. When curl is usedon an FTP URL to do transfer without any given user name or password, it usesthe nameanonymous
with the passwordftp@example.com
.
If you want to provide another user name and password, you can pass them on tocurl either with the-u, --user
option or embed the info in the URL:
curl --user daniel:secret ftp://example.com/downloadcurl ftp://daniel:secret@example.com/download