with System; use System;
with Adacurl; use Adacurl;
with Adacurl.easy; use Adacurl.Easy;
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
with Curl_Callbacks; use Curl_Callbacks;
with System.Address_To_Access_Conversions;
with Ada.Text_Io; use Ada.Text_Io;
procedure Ftpget is
---------------------------------------------------------------------------
package Ftpfile_Conv is new System.Address_To_Access_Conversions(Ftpfile);
use Ftpfile_Conv;
---------------------------------------------------------------------------
---------------------------------------------------------------------------
function fopen(Name : chars_ptr;
Mode : Chars_Ptr) return File_P;
pragma Import(C,fopen,"fopen");
---------------------------------------------------------------------------
---------------------------------------------------------------------------
function fclose(Stream : File_P) return Int;
pragma Import(C,fclose,"fclose");
---------------------------------------------------------------------------
Curl : CURL_P;
Res : CURLcode;
Rc : Int;
Ftp : aliased Ftpfile;
begin
Ftp.Filename := New_String("curl.tar.gz");
Ftp.Stream := System.Null_Address;
Res := Curl_Global_Init(CURL_GLOBAL_DEFAULT);
Curl := Curl_Easy_Init;
if Curl /= null then
Res := Curl_Easy_Setopt(Curl,
CURLOPT_URL,
New_String("ftp://ftp.sunet.se/pub/www/" &
"utilities/curl/curl-7.9.2.tar.gz"));
Res := Curl_Easy_Setopt(Curl,CURLOPT_WRITEFUNCTION,My_Fwrite'Access);
Res := Curl_Easy_Setopt(Curl,
CURLOPT_FILE,
To_Address(Ftp'Unchecked_Access));
Res := Curl_Easy_Setopt(Curl,CURLOPT_VERBOSE,1);
Res := Curl_Easy_Perform(Curl);
Curl_Easy_Cleanup(Curl);
if CURLE_OK /= Res then
Put_Line(Standard_Error,"curl told us " & CURLcode'Image(Res));
end if;
end if;
Rc := Fclose(Ftp.Stream);
Curl_Global_Cleanup;
end Ftpget;