FTP: Difference between revisions

1,912 bytes added ,  29 days ago
Added Ada using ASFML library (binding to SFML)
(Dialects of BASIC moved to the BASIC section.)
(Added Ada using ASFML library (binding to SFML))
 
(One intermediate revision by one other user not shown)
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}}==
Line 1,996 ⟶ 2,060:
{{libheader|ftplib}}
An embedded program so we can ask the C host to communicate with ''ftplib'' for us.
<syntaxhighlight lang="ecmascriptwren">/* ftpFTP.wren */
 
var FTPLIB_CONNMODE = 1
Line 2,163 ⟶ 2,227:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "ftpFTP.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
18

edits