Here is how you would connect to an anonymous FTP server using curl, meaning the FTP server does not require a username or password.
curl ftp://server1.example.com
The SFTP protocol would be used to connect to an SFTP server.
curl sftp://server1.example.com
The
-u or --user option
must be used if the FTP server requires a username and password to establish the connection.
curl --user john.doe:itsasecret ftp://server1.example.com
By default, curl will use your /home/username/.ssh/id_rsa (if it exists) private key when attempting to establish a connection to an SFTP server. The
--key option
can be used if you want to use some other private key file.
curl --user john.doe:itsasecret --key example.key sftp://server1.example.com
If the private key file is secured with a passphrase, the
--pass option
can be used to include the passphrase.
curl --user john.doe:itsasecret --key example.key --pass itsasecret sftp://server1.example.com
Once connected, the files and directories of the FTP server should be returned as output.
~]$ curl --user john.doe:itsasecret --key example.key --pass itsasecret sftp://server1.example.com
drwxrwxrwx 1 0 0 4096 Jun 24 02:28 OUTPUT
drwxrwxrwx 1 0 0 38 Jun 23 10:35 INPUT
-rw-r--r-- 1 0 0 24576 Jun 23 22:38 foo.txt
The
-T or --upload-file option
can be used to upload a file to the FTP server.
curl --user john.doe:itsasecret --key example.key --pass itsasecret --upload-file bar.txt sftp://server1.example.com