FTP: Difference between revisions

1,918 bytes added ,  18 days ago
Added Ada using ASFML library (binding to SFML)
m (→‎{{header|Wren}}: Minor tidy)
(Added Ada using ASFML library (binding to SFML))
 
Line 4:
Connect to a server, change directory, list its contents and download a file as binary using the FTP protocol. Use passive mode if available.
<br/><br/>
 
=={{header|Ada}}==
==={{libheader|ASFML|2.6.2}}===
The SFML library does not provide a passive mode.
 
<syntaxhighlight lang="ada">
with Ada.Text_IO;
with Sf.Network.Ftp;
with Sf.Network.IpAddress;
with Sf.System.Time;
 
procedure Main is
use Sf; use Sf.Network; use Sf.Network.Ftp;
FTP_Error : exception;
 
FTP_Object : constant sfFtp_Ptr := create;
 
procedure Check_Response (FTP_Response : sfFtpResponse_Ptr) is
Message : constant String := Response.getMessage (FTP_Response);
begin
Response.destroy (FTP_Response);
if not Response.isOk (FTP_Response) then
raise FTP_Error with Message;
else
Ada.Text_IO.Put_Line ("OK: " & Message);
end if;
end Check_Response;
 
procedure List_Directory (Path : String) is
Response : sfFtpListingResponse_Ptr;
begin
Response := getDirectoryListing (FTP_Object, Path);
if ListingResponse.isOk (Response) then
for Index in 0 .. ListingResponse.getCount (Response) - 1 loop
Ada.Text_IO.Put_Line (ListingResponse.getName (Response, Index));
end loop;
else
Ada.Text_IO.Put_Line (ListingResponse.getMessage (Response));
end if;
ListingResponse.destroy (Response);
end List_Directory;
 
begin
 
Check_Response
(connect (FTP_Object,
server => IpAddress.fromString ("speedtest.tele2.net"),
port => 21,
timeout => Sf.System.Time.sfSeconds (30.0)));
 
Check_Response (loginAnonymous (FTP_Object));
 
Check_Response (changeDirectory (FTP_Object, "/upload"));
Check_Response (changeDirectory (FTP_Object, "/"));
 
List_Directory (".");
 
Check_Response (download (FTP_Object,
remoteFile => "100KB.zip",
localPath => ".",
mode => sfFtpBinary));
destroy (FTP_Object);
end Main;
</syntaxhighlight>
 
=={{header|BASIC}}==
16

edits