1 .\" Copyright (c) 1998 Dag-Erling Coïdan Smørgrav
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 .Nd file transfer functions
57 .Fd #include <sys/param.h>
58 .Fd #include <stdio.h>
59 .Fd #include <fetch.h>
61 .Fn fetchParseURL "char *URL"
63 .Fn fetchFreeURL "struct url *URL"
65 .Fn fetchGetURL "char *URL" "char *flags"
67 .Fn fetchPutURL "char *URL" "char *flags"
69 .Fn fetchStatURL "char *URL" "struct url_stat *us" "char *flags"
71 .Fn fetchListURL "char *URL" "char *flags"
73 .Fn fetchGet "struct url *URL" "char *flags"
75 .Fn fetchPut "struct url *URL" "char *flags"
77 .Fn fetchStat "struct url *URL" "struct url_stat *us" "char *flags"
79 .Fn fetchList "struct url *" "char *flags"
81 .Fn fetchGetFile "struct url *u" "char *flags"
83 .Fn fetchPutFile "struct url *u" "char *flags"
85 .Fn fetchStatFile "struct url *URL" "struct url_stat *us" "char *flags"
87 .Fn fetchListFile "struct url *" "char *flags"
89 .Fn fetchGetHTTP "struct url *u" "char *flags"
91 .Fn fetchPutHTTP "struct url *u" "char *flags"
93 .Fn fetchStatHTTP "struct url *URL" "struct url_stat *us" "char *flags"
95 .Fn fetchListHTTP "struct url *" "char *flags"
97 .Fn fetchGetFTP "struct url *u" "char *flags"
99 .Fn fetchPutFTP "struct url *u" "char *flags"
101 .Fn fetchStatFTP "struct url *URL" "struct url_stat *us" "char *flags"
103 .Fn fetchListFTP "struct url *" "char *flags"
106 These functions implement a high-level library for retrieving and
107 uploading files using Uniform Resource Locators (URLs).
110 takes a URL in the form of a null-terminated string and splits it into
111 its components function according to the Common Internet Scheme Syntax
113 A regular expression which produces this syntax is:
115 <scheme>:(//(<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
118 Note that some components of the URL are not necessarily relevant to
120 For instance, the file scheme only needs the <scheme>
121 and <document> components.
123 The pointer returned by
125 should be freed using
131 constitute the recommended interface to the
134 They examine the URL passed to them to determine the transfer
135 method, and call the appropriate lower-level functions to perform the
139 argument is a string of characters which specify transfer options.
141 meaning of the individual flags is scheme-dependent, and is detailed
142 in the appropriate section below.
145 attempts to obtain the requested document's metadata and fill in the
146 structure pointed to by it's second argument.
149 structure is defined as follows in
160 attempts to list the contents of the directory pointed to by the URL
162 If successful, it returns a malloced array of
167 structure is defined as follows in
171 char name[MAXPATHLEN];
172 struct url_stat stat;
176 The list is terminated by an entry with an empty name.
178 The pointer returned by
180 should be freed using
192 except that they expect a pre-parsed URL in the form of a pointer to
195 rather than a string.
201 functions return a pointer to a stream which can be used to read or
202 write data from or to the requested document, respectively.
204 although the implementation details of the individual access methods
205 vary, it can generally be assumed that a stream returned by one of the
207 functions is read-only, and that a stream returned by one of the
209 functions is write-only.
214 provide access to documents which are files in a locally mounted file
216 Only the <document> component of the URL is used.
219 does not accept any flags.
224 (append to file) flag.
225 If that flag is specified, the data written to
226 the stream returned by
228 will be appended to the previous contents of the file, instead of
234 implement the FTP protocol as described in RFC959.
238 (passive) flag is specified, a passive (rather than active) connection
243 (high) flag is specified, data sockets will be allocated in the high
249 (direct) flag is specified,
253 will use a direct connection even if a proxy server is defined.
255 If no user name or password is given, the
257 library will attempt an anonymous login, with user name "ftp" and
264 functions implement the HTTP/1.1 protocol.
265 With a little luck, there's
266 even a chance that they comply with RFC2068.
270 (direct) flag is specified,
274 will use a direct connection even if a proxy server is defined.
276 Since there seems to be no good way of implementing the HTTP PUT
277 method in a manner consistent with the rest of the
281 is currently unimplemented.
284 returns a pointer to a
286 containing the individual components of the URL.
288 unable to allocate memory, or the URL is syntactically incorrect,
290 returns a NULL pointer.
294 functions return 0 on success and -1 on failure.
296 All other functions return a stream pointer which may be used to
297 access the requested document, or NULL if an error occurred.
300 uses the Common Error Library
303 The error code passed to
307 .It Bq Er FETCH_ABORT
310 Authentication failed
313 .It Bq Er FETCH_EXISTS
318 Informational response
319 .It Bq Er FETCH_MEMORY
321 .It Bq Er FETCH_MOVED
323 .It Bq Er FETCH_NETWORK
327 .It Bq Er FETCH_PROTO
329 .It Bq Er FETCH_RESOLV
331 .It Bq Er FETCH_SERVER
335 .It Bq Er FETCH_TIMEOUT
337 .It Bq Er FETCH_UNAVAIL
338 File is not available
339 .It Bq Er FETCH_UNKNOWN
345 The accompanying error message includes a protocol-specific error code
346 and message, e.g. "File is not available (404 Not Found)"
348 The FTP and HTTP related functions use the
352 environment variables, respectively, as the address of a proxy server
353 to use for transferring files.
364 .%T Uniform Resource Locators (URL)
374 .%B Hypertext Transfer Protocol -- HTTP/1.1
381 .%B File Transfer Protocol
387 library uses the Common Error library, and applications which link
390 must therefore also link with
395 library first appeared in
400 library was mostly written by
401 .An Dag-Erling Coïdan Smørgrav Aq des@FreeBSD.org
402 with numerous suggestions from
403 .An Jordan K. Hubbard Aq jkh@FreeBSD.org ,
404 .An Eugene Skepner Aq eu@qub.com
405 and other FreeBSD developers.
406 It replaces the older
409 .An Poul-Henning Kamp Aq pkh@FreeBSD.org
411 .An Jordan K. Hubbard Aq jkh@FreeBSD.org .
413 This manual page was written by
414 .An Dag-Erling Coïdan Smørgrav Aq des@FreeBSD.org
416 Some parts of the library are not yet implemented.
422 and FTP proxy support.
424 There's no way to select a proxy at run-time other than setting the
428 environment variables as appropriate.
429 There is also no way to stop the
430 FTP and HTTP functions from trying to use a proxy if these variables
433 HTTP authentication doesn't work.
434 I'm not sure that's a bug in my
435 code; as far as I can determine,
437 handles HTTP/1.1 basic authentication correctly as outlined in
438 RFC2068, but I haven't been able to find an HTTP server that honors
439 the Authentication: header field.
442 does not attempt to interpret and respond to authentication requests
443 from the HTTP server.
445 No attempt is made to encode spaces etc. within URLs.
447 document part of an URLshould be replaced with "%20" in HTTP URLs and
450 Error numbers are unique only within a certain context; the error
451 codes used for FTP and HTTP overlap, as do those used for resolver and
453 For instance, error code 202 means "Command not
454 implemented, superfluous at this site" in an FTP context and
455 "Accepted" in an HTTP context.
458 does not check that the result of an MDTM command is a valid date.
460 The HTTP code needs a complete rewrite, or at least a serious cleanup.
462 The man page is poorly written and produces badly formatted text.