Up |
_networkSetFTPget
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).
Prototype :
fun [ObjNetwork S W] ObjNetwork
- ObjNetwork : a network object created with _networkCreate.
- S : an url (like "ftp://ftp.example.com/file.ext" or "ftp://user:password@192.168.0.25"). It should be in the
format :
ftp://host:port/path
. If the port is not given, the default port is determined from the protocol - W : a write-reference file to save the received content.The old content, if any, will be overwritten, be careful. Can be nil. Note : the file will be created if no error is returned by the server.
Return : ObjNetwork the same object or nil if error.
See also :
Example :
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 !
Note :
You could set any supplemental options like an authentification with _networkSetOption