FTP: Difference between revisions
m
syntax highlighting fixup automation
(Added Bash / Unix Shell Implementation) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 7:
=={{header|BaCon}}==
Using libCURL.
<
PRAGMA INCLUDE <curl/curl.h>
Line 23:
curl_easy_cleanup(easyhandle)
CLOSE FILE download</
Full native implementation without dependency to external libraries.
<
LOCAL pasv$, data$, response$
Line 71:
PRINT interact$("QUIT", ftp, 0)
CLOSE NETWORK ftp</
=={{header|Batch File}}==
This uses the native FTP.EXE in Windows. I am not sure, but I think FTP.EXE client does not support passive mode.
<
::Batch File Implementation
Line 98:
echo.get %download%
echo.disconnect
)|ftp -n</
{{Out}}
<pre>\Desktop>RCFTP
Line 130:
=={{header|C}}==
Using [http://nbpfaus.net/~pfau/ftplib/ ftplib]
<syntaxhighlight lang="c">
#include <ftplib.h>
Line 148:
return 0;
}
</syntaxhighlight>
=={{header|C++}}==
Line 154:
Using [http://nbpfaus.net/~pfau/ftplib/ ftplib], [https://github.com/saur0n/libftpxx libftp++]
<
libftp++ C++ classes for ftplib C ftp library
Line 493:
}
/* END */
</syntaxhighlight>
{{Out}}
Line 539:
Using package [http://code.kepibu.org/cl-ftp/ cl-ftp].
<
(with-ftp-connection (conn :hostname "ftp.hq.nasa.gov"
Line 547:
(let ((filename "Gravity in the Brain.mp3"))
(retrieve-file conn filename filename :type :binary)))
</syntaxhighlight>
{{Out}}
<pre>
Line 565:
=={{header|Erlang}}==
Erlang implementation using ftp module.
<
%%%-------------------------------------------------------------------
%%% To execute in shell, Run the following commands:-
Line 608:
io:format("Closing connection to FTP Server"),
ftp:close(Pid).
</syntaxhighlight>
Line 614:
=={{header|FutureBasic}}==
FB for Mac easily interfaces with the terminal command line. NOTE: The curl command line tool used in this example offers upload and sending capabilities. It supports FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS, FILE, POP3, IMAP, SMTP, RTMP and RTSP.
<
include "NSLog.incl"
Line 646:
HandleEvents
</syntaxhighlight>
{{output}}
<pre style="font-size: 12px">
Line 676:
=={{header|Go}}==
Using the FTP package from [https://godoc.org/github.com/stacktic/ftp github.com/stacktic/ftp].
<
import (
Line 737:
fmt.Println("Wrote", n, "bytes to", file)
}</
Line 746:
Dependencies are automatically loaded with the @Grab annotation.
let's say the code is saved in the file ftpTest.groovy:
<syntaxhighlight lang="groovy">
@Grab(group='commons-net', module='commons-net', version='2.0')
import org.apache.commons.net.ftp.FTPClient
Line 761:
}
println(" ...Done.");
</syntaxhighlight>
By typing groovy ftpTest.groovy, you should see a README.html file on your directory.
<pre>
Line 782:
Example uses [https://hackage.haskell.org/package/ftphs <tt>ftphs</tt>] package:
<
import Control.Exception (bracket)
Line 812:
-- Download in binary mode
(fileData, _) <- getbinary h "linux-0.01.tar.gz.sign"
print fileData</
=={{header|J}}==
<
gethttp 'ftp://anonymous:example@ftp.hq.nasa.gov/pub/issoutreach/Living%20in%20Space%20Stories%20(MP3%20Files)/'
-rw-rw-r-- 1 109 space-station 2327118 May 9 2005 09sept_spacepropulsion.mp3
Line 830:
-rw-rw-r-- 1 109 space-station 1134654 May 9 2005 When Space Makes you Dizzy.mp3
#file=: gethttp rplc&(' ';'%20') 'ftp://anonymous:example@ftp.hq.nasa.gov/pub/issoutreach/Living in Space Stories (MP3 Files)/We have a solution.mp3'
772075</
=={{header|Java}}==
requires apache.commons.net
<
import java.io.IOException;
import java.io.OutputStream;
Line 906:
}
}
}</
Output:
Line 954:
{{works with|Julia|0.6}}
<
ftp = FTP(hostname = "ftp.ed.ac.uk", username = "anonymous")
Line 961:
bytes = read(download(ftp, "make.notes.tar"))
close(ftp)</
=={{header|Kotlin}}==
Line 996:
</pre>
Next, you need to compile the following Kotlin program, linking against ftplib.klib.
<
import kotlinx.cinterop.*
Line 1,013:
FtpQuit(vnbuf)
nativeHeap.free(nbuf)
}</
Finally, the resulting .kexe file should be executed producing something similar to the following output:
<pre>
Line 1,034:
=={{header|Lingo}}==
{{libheader|Curl Xtra}}
<
ch = xtra("Curl").new()
url = "ftp://domain.com"
Line 1,051:
ch.setOption(CURLOPT_URL, url & filename)
ch.setDestinationFile(_movie.path & filename)
res = ch.exec()</
=={{header|LiveCode}}==
<
put url "ftp://ftp.hq.nasa.gov/" into listing
repeat for each line ftpln in listing
Line 1,092:
e.g. to know the working directory, issue "pwd", we could issue "list" for above too,
but using an url with slash on the end with the ftp protocol causes a dir listing by default.
put libURLftpCommand("PWD",ftp.example.org)</
=={{header|Nim}}==
Line 1,098:
{{works with|Nim|1.4}}
<
const
Line 1,127:
echo await ftp.send("QUIT") # Disconnect.
waitFor main()</
{{out}}
Line 1,149:
=={{header|Perl}}==
<
# set server and credentials
Line 1,170:
$f->type('binary');
$local = $f->get('512KB.zip');
print "Your file was stored as $local in the current directory\n";</
{{out}}
<pre>Currently 20 files in the 'upload' directory
Line 1,177:
=={{header|Phix}}==
{{libheader|Phix/libcurl}}
<!--<
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- libcurl, allocate, file i/o</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">libcurl</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 1,202:
<span style="color: #0000FF;">?{</span><span style="color: #008000;">"error"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</
{{out}}
<pre>
Line 1,227:
=={{header|PHP}}==
<
$server = "speedtest.tele2.net";
$user = "anonymous";
Line 1,248:
} else {
echo "failed to download file";
}</
{{out}}
<pre>
Line 1,279:
=={{header|PicoLisp}}==
Passive is the default behavior of 'curl'
<
(while (line)
(prinl @) ) )
(call "curl" "-s" "-o" "sha256sums.asc" "ftp://kernel.org/pub/site/sha256sums.asc")</
Output:
<pre>README
Line 1,290:
=={{header|Python}}==
{{works with|Python|2.7.10}}
<syntaxhighlight lang="python">
from ftplib import FTP
ftp = FTP('kernel.org')
Line 1,299:
print ftp.retrbinary('RETR README', open('README', 'wb').write)
ftp.quit()
</syntaxhighlight>
=={{header|Racket}}==
Note: <tt>net/ftp</tt> in Racket uses passive mode exclusively.
<
#lang racket
(require net/ftp)
Line 1,319:
(ftp-download-file conn "." "README")
(ftp-close-connection conn))
</syntaxhighlight>
=={{header|Raku}}==
Line 1,325:
{{works with|rakudo|2018.04}}
<syntaxhighlight lang="raku"
my $host = 'speedtest.tele2.net';
Line 1,341:
say $_<name> for $ftp.ls;
$ftp.get( '1KB.zip', :binary );</
{{out}}
Line 1,364:
=={{header|REBOL}}==
<syntaxhighlight lang="rebol">
system/schemes/ftp/passive: on
print read ftp://kernel.org/pub/linux/kernel/
write/binary %README read/binary ftp://kernel.org/pub/linux/kernel/README
</syntaxhighlight>
=={{header|Ruby}}==
<
Net::FTP.open('ftp.ed.ac.uk', "anonymous","aaa@gmail.com" ) do |ftp|
Line 1,378:
puts ftp.list
ftp.getbinaryfile("make.notes.tar")
end</
The connection is closed automatically at the end of the block.
=={{header|Rust}}==
Using crate <code>ftp</code> version 3.0.1
<
use ftp::FtpStream;
Line 1,397:
copy(&mut stream, &mut file)?;
Ok(())
}</
=={{header|Scala}}==
{{libheader|commons-net}}
<
import org.apache.commons.net.ftp.{FTPClient, FTPFile, FTPReply}
Line 1,478:
ftpClient.logout
}.isFailure) println(s"Failure.")
}</
{{Out}}See it in running in your browser by [https://scastie.scala-lang.org/3Lq8ehzIQTCuAOPXWofNLw Scastie (JVM)].
Line 1,485:
[http://seed7.sourceforge.net/libraries/ftp.htm#openFtp(in_string) open] and handle an
[http://seed7.sourceforge.net/libraries/ftp.htm#ftpFileSys ftpFileSys].
<
include "ftp.s7i";
Line 1,502:
writeln(getFile(ftp, "README"));
close(ftp);
end func;</
=={{header|Sidef}}==
{{trans|Ruby}}
<
var ftp = %s'Net::FTP'.new('ftp.ed.ac.uk', Passive => 1);
Line 1,514:
ftp.binary; # set binary mode
ftp.get("make.notes.tar");
ftp.quit;</
=={{header|Tcl}}==
===Using package ftp===
<syntaxhighlight lang="tcl">
package require ftp
Line 1,528:
::ftp::Type $conn binary
::ftp::Get $conn README README
</syntaxhighlight>
===Using a virtual file system===
An alternative approach that uses the package [http://sourceforge.net/projects/tclvfs/ TclVFS] to access ftp:// paths as a virtual file system.
<
package require vfs::urltype
vfs::urltype::Mount ftp
Line 1,546:
}
file copy README [file join $dir README]
</syntaxhighlight>
The file <tt>vfsftpfix.tcl</tt> with the passive mode patch (see http://wiki.tcl.tk/12837):
<
# Replace vfs::ftp::Mount to enable vfs::ftp to work in passive
# mode and make that the default.
Line 1,600:
return $fd
}
</syntaxhighlight>
=={{header|UNIX Shell}}==
Uses sftp which os available on all Linux distress by default. The commands are identical to ftp. This example uses the public free sftp server at test.rebex.net , the credentials are demo/password :
<
Aamrun $ sftp demo@test.rebex.net
Password:
Line 1,623:
sftp> exit
Aamrun$
</syntaxhighlight>
=={{header|Wren}}==
Line 1,629:
{{libheader|ftplib}}
An embedded program so we can ask the C host to communicate with ''ftplib'' for us.
<
var FTPLIB_CONNMODE = 1
Line 1,660:
ftp.dir("", ".")
ftp.get("ftp.README", "README", FTPLIB_ASCII)
ftp.quit()</
<br>
We now embed this in the following C program, compile and run it.
<
#include <stdio_ext.h>
#include <stdlib.h>
Line 1,812:
free(script);
return 0;
}</
{{out}}
Line 1,835:
=={{header|zkl}}==
Using the cURL library, doing this from the REPL. Moving around in the tree isn't supported.
<
zkl: var d=cURL().get("ftp.hq.nasa.gov/pub/issoutreach/Living in Space Stories (MP3 Files)/")
L(Data(2,567),1630,23) // downloaded listing, 1630 bytes of header, 23 bytes of trailer
Line 1,846:
L(Data(1,136,358),1681,23)
zkl: File("foo.mp3","w").write(d[0][1681,-23])
1134654 // note that this matches size in listing</
The resulting file foo.mp3 has a nice six minute description of what can happen when returning from space.
|