Reputation: 87
I am trying to implement libcurl for both SFTP and FTP transfers. During transfers, I want to use the SFTP protocol. In case that fails, it would be nice if libcurl could try FTP before completely giving up.
The purpose is that the user will send off data to a remote server. Internally, if found that it is not a sftp-server then fall down to the possibility of it being a ftp-server.
I have been concatenating the url with either "sftp://" or "ftp://". And I tried to do the following,
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl_handle, CURLOPT_PROTOCOLS, CURLPROTO_SFTP | CURLPROTO_FTP);
curl_easy_setopt(curl_handle, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_SFTP | CURLPROTO_FTP);
Any suggestions? Could some one direct me to an example? Or at least let me know if I am headed in the right direction.
Upvotes: 0
Views: 267
Reputation: 58124
CURLOPT_REDIR_PROTOCOLS is a bitmask you set to tell libcurl which protocols to allow a redirect to. The redirect can in fact only be received over HTTP. A redirect is an instruction set from the server to instead try the request on a different URL.
SFTP has no redirection feature so there's no point for you to set this bitmask as long as you don't use HTTP.
libcurl has no way to automatically try a different protocol if one fails, such logic has to be implemented by your application.
Upvotes: 1