Up |
Prepare an FTP GET request.
If the file doesn't exist or if a folder path only is given, a list of the content
directory will be retrieved (included rights, file sizes, dates, etc).
fun [ObjNetwork S W] ObjNetwork
ftp://host:port/path
. If the port is not given,
the default port is determined from the protocolReturn : ObjNetwork the same object or nil if error.
Get a file from an anonymous ftp server
typeof Net = ObjNetwork;;
var totalsize = 0;;
fun cbHTTPget (obj, user_parameter, err, content, size)=
set totalsize = totalsize+size;
_fooS "cbHTTPget :>>>";
_fooId err;
_fooS strcat "SIZE = " itoa size;
_fooS strcat "TOTAL = " itoa totalsize;
0;;
fun downloadFtp (url)=
/* prepare the request */
_networkSetMode Net NETWORK_NOTHREADED;
_networkCBdownload Net @cbHTTPget 0;
_networkSetFTPget Net url _getmodifypack "tests/syspack/network/gcc.deb";
/* perform the request */
_fooS strcat "PERFORM : " itoa _networkPerform Net;
/* display the error result */
_fooS sprintf "AFTER error number : %d error string %s" _networkGetError Net;
0;;
fun main ()=
_showconsole;
...
// checks the library and create the network Scol object
...
downloadFtp "ftp://ftp.fr.debian.org/debian/pool/main/g/gcc-4.4/gcc-4.4_4.4.5-8_i386.deb";
...
0;;
Get a file from an basic private ftp server
typeof Net = ObjNetwork;;
var totalsize = 0;;
fun cbHTTPget (obj, user_parameter, err, content, size)=
set totalsize = totalsize+size;
_fooS "cbHTTPget :>>>";
_fooId err;
_fooS strcat "SIZE = " itoa size;
_fooS strcat "TOTAL = " itoa totalsize;
0;;
fun downloadFtp (url)=
/* prepare the request */
_networkSetMode Net NETWORK_NOTHREADED;
_networkCBdownload Net @cbHTTPget 0;
_networkSetFTPget Net url _getmodifypack "tests/syspack/network/file.ext";
_networkSetOption Net NETWORK_OPTION_USERNAME "login";
_networkSetOption Net NETWORK_OPTION_PASSWORD "password";
/* perform the request */
_fooS strcat "PERFORM : " itoa _networkPerform Net;
/* display the error result */
_fooS sprintf "AFTER error number : %d error string %s" _networkGetError Net;
0;;
fun main ()=
_showconsole;
...
// checks the library and create the network Scol object
...
downloadFtp "ftp://some.domain.tld/folder/file.ext";
...
0;;
You may include login and password in the url : "ftp://login:password@some.domain.tld/folder/file.ext" and remove the two _networkSetOption lines.
The basic authentification is not safe, login and password are sent in plain text !
You could set any supplemental options like an authentification with _networkSetOption