FTP: Difference between revisions

2,551 bytes added ,  6 years ago
Added Kotlin
(Added Julia language)
(Added Kotlin)
Line 360:
 
close(ftp)</lang>
 
=={{header|Kotlin}}==
{{trans|C}}
{{libheader|ftplib}}
{{works with|Ubuntu 14.04}}
Assuming that ftplib is already installed on your system in the default location(s), you first need to build ftplib.klib using the following .def file and the cinterop tool. As the Netbuf struct is not defined in ftplib.h (but is in ftplib.c) it has been included in the .def file so that the tool can deal with it (and its alias 'netbuf') properly from a Kotlin perspective.
 
<pre>
headers = /usr/include/ftplib.h
linkerOpts.linux = -L/usr/lib -lftp
 
---
 
#include <sys/time.h>
 
struct NetBuf {
char *cput,*cget;
int handle;
int cavail,cleft;
char *buf;
int dir;
netbuf *ctrl;
netbuf *data;
int cmode;
struct timeval idletime;
FtpCallback idlecb;
void *idlearg;
int xfered;
int cbbytes;
int xfered1;
char response[256];
};
</pre>
Next, you need to compile the following Kotlin program, linking against ftplib.klib.
<lang scala>// Kotlin Native v0.6
 
import kotlinx.cinterop.*
import ftplib.*
 
fun main(args: Array<String>) {
val nbuf = nativeHeap.allocPointerTo<netbuf>()
FtpInit()
FtpConnect("ftp.easynet.fr", nbuf.ptr)
val vnbuf = nbuf.value
FtpLogin("anonymous", "ftptest@example.com", vnbuf)
FtpOptions(FTPLIB_CONNMODE, FTPLIB_PASSIVE.toLong(), vnbuf)
FtpChdir("/debian/", vnbuf)
FtpDir(null, ".", vnbuf)
FtpGet("ftp.README", "README.html", FTPLIB_ASCII.toByte(), vnbuf)
FtpQuit(vnbuf)
nativeHeap.free(nbuf)
}</lang>
Finally, the resulting .kexe file should be executed producing something similar to the following output:
<pre>
drwxr-xr-x 23 1002 1002 4096 Dec 9 09:44 dists
drwxr-xr-x 4 1002 1002 4096 Mar 3 19:52 doc
-rw-r--r-- 1 1002 1002 361654 Mar 3 20:49 extrafiles
drwxr-xr-x 3 1002 1002 4096 Mar 3 20:42 indices
-rw-r--r-- 1 1002 1002 14948661 Mar 3 20:42 ls-lR.gz
drwxr-xr-x 5 1002 1002 4096 Dec 19 2000 pool
drwxr-xr-x 4 1002 1002 4096 Nov 17 2008 project
-rw-r--r-- 1 1002 1002 1186 Dec 9 09:42 README
-rw-r--r-- 1 1002 1002 1290 Jun 26 2010 README.CD-manufacture
-rw-r--r-- 1 1002 1002 2903 Dec 9 09:42 README.html
-rw-r--r-- 1 1002 1002 291 Mar 4 2017 README.mirrors.html
-rw-r--r-- 1 1002 1002 86 Mar 4 2017 README.mirrors.txt
drwxr-xr-x 3 1002 1002 4096 Oct 10 2012 tools
drwxr-xr-x 23 1002 1002 4096 Jun 17 2017 zzz-dists
</pre>
 
=={{header|Lingo}}==
9,490

edits