2 .\" Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 .Nd file transfer functions
68 .Fn fetchMakeURL "const char *scheme" "const char *host" "int port" "const char *doc" "const char *user" "const char *pwd"
70 .Fn fetchParseURL "const char *URL"
72 .Fn fetchFreeURL "struct url *u"
74 .Fn fetchXGetURL "const char *URL" "struct url_stat *us" "const char *flags"
76 .Fn fetchGetURL "const char *URL" "const char *flags"
78 .Fn fetchPutURL "const char *URL" "const char *flags"
80 .Fn fetchStatURL "const char *URL" "struct url_stat *us" "const char *flags"
82 .Fn fetchListURL "const char *URL" "const char *flags"
84 .Fn fetchXGet "struct url *u" "struct url_stat *us" "const char *flags"
86 .Fn fetchGet "struct url *u" "const char *flags"
88 .Fn fetchPut "struct url *u" "const char *flags"
90 .Fn fetchStat "struct url *u" "struct url_stat *us" "const char *flags"
92 .Fn fetchList "struct url *u" "const char *flags"
94 .Fn fetchXGetFile "struct url *u" "struct url_stat *us" "const char *flags"
96 .Fn fetchGetFile "struct url *u" "const char *flags"
98 .Fn fetchPutFile "struct url *u" "const char *flags"
100 .Fn fetchStatFile "struct url *u" "struct url_stat *us" "const char *flags"
102 .Fn fetchListFile "struct url *u" "const char *flags"
104 .Fn fetchXGetHTTP "struct url *u" "struct url_stat *us" "const char *flags"
106 .Fn fetchGetHTTP "struct url *u" "const char *flags"
108 .Fn fetchPutHTTP "struct url *u" "const char *flags"
110 .Fn fetchStatHTTP "struct url *u" "struct url_stat *us" "const char *flags"
112 .Fn fetchListHTTP "struct url *u" "const char *flags"
114 .Fn fetchXGetFTP "struct url *u" "struct url_stat *us" "const char *flags"
116 .Fn fetchGetFTP "struct url *u" "const char *flags"
118 .Fn fetchPutFTP "struct url *u" "const char *flags"
120 .Fn fetchStatFTP "struct url *u" "struct url_stat *us" "const char *flags"
122 .Fn fetchListFTP "struct url *u" "const char *flags"
124 These functions implement a high-level library for retrieving and
125 uploading files using Uniform Resource Locators (URLs).
128 takes a URL in the form of a null-terminated string and splits it into
129 its components function according to the Common Internet Scheme Syntax
131 A regular expression which produces this syntax is:
133 <scheme>:(//(<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
136 If the URL does not seem to begin with a scheme name, the following
139 ((<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
142 Note that some components of the URL are not necessarily relevant to
144 For instance, the file scheme only needs the <scheme> and <document>
150 return a pointer to a
152 structure, which is defined as follows in
155 #define URL_SCHEMELEN 16
156 #define URL_USERLEN 256
157 #define URL_PWDLEN 256
160 char scheme[URL_SCHEMELEN+1];
161 char user[URL_USERLEN+1];
162 char pwd[URL_PWDLEN+1];
163 char host[MAXHOSTNAMELEN+1];
174 field stores the time value for
175 .Li If-Modified-Since
178 The pointer returned by
182 should be freed using
189 constitute the recommended interface to the
192 They examine the URL passed to them to determine the transfer
193 method, and call the appropriate lower-level functions to perform the
196 also returns the remote document's metadata in the
198 structure pointed to by the
204 argument is a string of characters which specify transfer options.
206 meaning of the individual flags is scheme-dependent, and is detailed
207 in the appropriate section below.
210 attempts to obtain the requested document's metadata and fill in the
211 structure pointed to by its second argument.
214 structure is defined as follows in
224 If the size could not be obtained from the server, the
227 If the modification time could not be obtained from the server, the
229 field is set to the epoch.
230 If the access time could not be obtained from the server, the
232 field is set to the modification time.
235 attempts to list the contents of the directory pointed to by the URL
237 If successful, it returns a malloced array of
242 structure is defined as follows in
247 struct url_stat stat;
251 The list is terminated by an entry with an empty name.
253 The pointer returned by
255 should be freed using
269 except that they expect a pre-parsed URL in the form of a pointer to
272 rather than a string.
279 functions return a pointer to a stream which can be used to read or
280 write data from or to the requested document, respectively.
282 although the implementation details of the individual access methods
283 vary, it can generally be assumed that a stream returned by one of the
287 functions is read-only, and that a stream returned by one of the
289 functions is write-only.
295 provide access to documents which are files in a locally mounted file
297 Only the <document> component of the URL is used.
302 do not accept any flags.
307 (append to file) flag.
308 If that flag is specified, the data written to
309 the stream returned by
311 will be appended to the previous contents of the file, instead of
318 implement the FTP protocol as described in RFC959.
322 (not passive) flag is specified, an active (rather than passive)
323 connection will be attempted.
327 flag is supported for compatibility with earlier versions where active
328 connections were the default.
329 It has precedence over the
331 flag, so if both are specified,
333 will use a passive connection.
337 (low) flag is specified, data sockets will be allocated in the low (or
338 default) port range instead of the high port range (see
343 (direct) flag is specified,
348 will use a direct connection even if a proxy server is defined.
350 If no user name or password is given, the
352 library will attempt an anonymous login, with user name "anonymous"
353 and password "anonymous@<hostname>".
360 functions implement the HTTP/1.1 protocol.
361 With a little luck, there is
362 even a chance that they comply with RFC2616 and RFC2617.
366 (direct) flag is specified,
371 will use a direct connection even if a proxy server is defined.
375 (if-modified-since) flag is specified, and
384 will send a conditional
385 .Li If-Modified-Since
386 HTTP header to only fetch the content if it is newer than
389 Since there seems to be no good way of implementing the HTTP PUT
390 method in a manner consistent with the rest of the
394 is currently unimplemented.
396 Apart from setting the appropriate environment variables and
397 specifying the user name and password in the URL or the
399 the calling program has the option of defining an authentication
400 function with the following prototype:
403 .Fn myAuthMethod "struct url *u"
405 The callback function should fill in the
409 fields in the provided
411 and return 0 on success, or any other value to indicate failure.
413 To register the authentication callback, simply set
416 The callback will be used whenever a site requires authentication and
417 the appropriate environment variables are not set.
419 This interface is experimental and may be subject to change.
422 returns a pointer to a
424 containing the individual components of the URL.
426 unable to allocate memory, or the URL is syntactically incorrect,
428 returns a NULL pointer.
432 functions return 0 on success and -1 on failure.
434 All other functions return a stream pointer which may be used to
435 access the requested document, or NULL if an error occurred.
437 The following error codes are defined in
440 .It Bq Er FETCH_ABORT
443 Authentication failed
446 .It Bq Er FETCH_EXISTS
451 Informational response
452 .It Bq Er FETCH_MEMORY
454 .It Bq Er FETCH_MOVED
456 .It Bq Er FETCH_NETWORK
460 .It Bq Er FETCH_PROTO
462 .It Bq Er FETCH_RESOLV
464 .It Bq Er FETCH_SERVER
468 .It Bq Er FETCH_TIMEOUT
470 .It Bq Er FETCH_UNAVAIL
471 File is not available
472 .It Bq Er FETCH_UNKNOWN
478 The accompanying error message includes a protocol-specific error code
479 and message, e.g.\& "File is not available (404 Not Found)"
481 .Bl -tag -width ".Ev FETCH_BIND_ADDRESS"
482 .It Ev FETCH_BIND_ADDRESS
483 Specifies a hostname or IP address to which sockets used for outgoing
484 connections will be bound.
486 Default FTP login if none was provided in the URL.
487 .It Ev FTP_PASSIVE_MODE
490 forces the FTP code to use active mode.
491 If set to any other value, forces passive mode even if the application
492 requested active mode.
494 Default FTP password if the remote server requests one and none was
497 URL of the proxy to use for FTP requests.
498 The document part is ignored.
499 FTP and HTTP proxies are supported; if no scheme is specified, FTP is
501 If the proxy is an FTP proxy,
505 as user name to the proxy, where
507 is the real user name, and
509 is the name of the FTP server.
511 If this variable is set to an empty string, no proxy will be used for
512 FTP requests, even if the
520 Specifies HTTP authorization parameters as a colon-separated list of
522 The first and second item are the authorization scheme and realm
523 respectively; further items are scheme-dependent.
528 authorization methods are supported.
530 Both methods require two parameters: the user name and
531 password, in that order.
533 This variable is only used if the server requires authorization and
534 no user name or password was specified in the URL.
536 URL of the proxy to use for HTTP requests.
537 The document part is ignored.
538 Only HTTP proxies are supported for HTTP requests.
539 If no port number is specified, the default is 3128.
541 Note that this proxy will also be used for FTP documents, unless the
548 .It Ev HTTP_PROXY_AUTH
549 Specifies authorization parameters for the HTTP proxy in the same
554 This variable is used if and only if connected to an HTTP proxy, and
555 is ignored if a user and/or a password were specified in the proxy
558 Specifies the referrer URL to use for HTTP requests.
561 the document URL will be used as referrer URL.
562 .It Ev HTTP_USER_AGENT
563 Specifies the User-Agent string to use for HTTP requests.
564 This can be useful when working with HTTP origin or proxy servers that
565 differentiate between user agents.
567 Specifies a file to use instead of
569 to look up login names and passwords for FTP sites.
572 for a description of the file format.
573 This feature is experimental.
575 Either a single asterisk, which disables the use of proxies
576 altogether, or a comma- or whitespace-separated list of hosts for
577 which proxies should not be used.
584 To access a proxy server on
585 .Pa proxy.example.com
588 environment variable in a manner similar to this:
590 .Dl HTTP_PROXY=http://proxy.example.com:8080
592 If the proxy server requires authentication, there are
593 two options available for passing the authentication data.
594 The first method is by using the proxy URL:
596 .Dl HTTP_PROXY=http://<user>:<pwd>@proxy.example.com:8080
598 The second method is by using the
600 environment variable:
601 .Bd -literal -offset indent
602 HTTP_PROXY=http://proxy.example.com:8080
603 HTTP_PROXY_AUTH=basic:*:<user>:<pwd>
606 To disable the use of a proxy for an HTTP server running on the local
610 .Bd -literal -offset indent
611 NO_PROXY=localhost,127.0.0.1
621 .%B File Transfer Protocol
629 .%T How to Use Anonymous FTP
637 .%T Uniform Resource Locators (URL)
649 .%B Hypertext Transfer Protocol -- HTTP/1.1
661 .%B HTTP Authentication: Basic and Digest Access Authentication
667 library first appeared in
673 library was mostly written by
674 .An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org
675 with numerous suggestions and contributions from
676 .An Jordan K. Hubbard Aq jkh@FreeBSD.org ,
677 .An Eugene Skepner Aq eu@qub.com ,
678 .An Hajimu Umemoto Aq ume@FreeBSD.org ,
679 .An Henry Whincup Aq henry@techiebod.com ,
680 .An Jukka A. Ukkonen Aq jau@iki.fi ,
681 .An Jean-Fran\(,cois Dockes Aq jf@dockes.org
683 It replaces the older
686 .An Poul-Henning Kamp Aq phk@FreeBSD.org
688 .An Jordan K. Hubbard Aq jkh@FreeBSD.org .
690 This manual page was written by
691 .An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
693 Some parts of the library are not yet implemented.
699 and FTP proxy support.
701 There is no way to select a proxy at run-time other than setting the
705 environment variables as appropriate.
708 does not understand or obey 305 (Use Proxy) replies.
710 Error numbers are unique only within a certain context; the error
711 codes used for FTP and HTTP overlap, as do those used for resolver and
713 For instance, error code 202 means "Command not
714 implemented, superfluous at this site" in an FTP context and
715 "Accepted" in an HTTP context.
718 does not check that the result of an MDTM command is a valid date.
720 The man page is incomplete, poorly written and produces badly
723 The error reporting mechanism is unsatisfactory.
725 Some parts of the code are not fully reentrant.