function ReadFromStream(Buffer: PAnsiChar; Size, Count: Integer;
Stream: TStream): Integer; cdecl;
begin
Result:= Stream.Read(Buffer^,Size*Count) div Size;
end;
function SaveToStream(Buffer: PAnsiChar; Size, Count: Integer;
Stream: TStream): Integer; cdecl;
begin
Result:= Stream.Write(Buffer^,Size*Count) div Size;
end;
function Subir(Usuario, Clave, URL, Archivo: AnsiString): Boolean;
var
Curl: TCURL;
Stream: TFileStream;
begin
Result:= FALSE;
Curl:= curl_easy_init;
if Curl <> nil then
try
if curl_easy_setopt(Curl, CURLOPT_VERBOSE, TRUE) <> CURLE_OK then
Exit;
if curl_easy_setopt(Curl, CURLOPT_USE_SSL, CURLUSESSL_ALL) <> CURLE_OK then
Exit;
if curl_easy_setopt(Curl, CURLOPT_SSL_VERIFYPEER, FALSE) <> CURLE_OK then
Exit;
if curl_easy_setopt(Curl, CURLOPT_USERNAME, PAnsiChar(Usuario)) <> CURLE_OK then
Exit;
if curl_easy_setopt(Curl, CURLOPT_PASSWORD, PAnsiChar(Clave)) <> CURLE_OK then
Exit;
if curl_easy_setopt(Curl, CURLOPT_URL, PAnsiChar(URL)) <> CURLE_OK then
Exit;
if curl_easy_setopt(Curl, CURLOPT_READFUNCTION, @ReadFromStream) <> CURLE_OK then
Exit;
Stream:= TFileStream.Create(Archivo,fmOpenRead);
try
if curl_easy_setopt(Curl, CURLOPT_INFILE, Stream) <> CURLE_OK then
Exit;
if curl_easy_setopt(Curl, CURLOPT_UPLOAD, TRUE) <> CURLE_OK then
Exit;
Result:= curl_easy_perform(Curl) = CURLE_OK;
finally
Stream.Free;
end;
finally
curl_easy_cleanup(Curl);
end;
end;
Subir('test','test','sftp://169.254.0.2:999/2.txt','C:\ART.DAT');