~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to ftp_lite/doc/ftp_lite.html

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<head>
 
2
<title>FTP-Lite Manual</title>
 
3
</head>
 
4
 
 
5
<body bgcolor=white>
 
6
 
 
7
<h1>FTP-Lite Manual</h1>
 
8
<b>Version 0.4, 27 August 2004</b>
 
9
 
 
10
<h2>Table of Contents</h2>
 
11
 
 
12
<ul>
 
13
<li> <a href=#front_matter>Front Matter</a>
 
14
<li> <a href=#introduction>Introduction</a>
 
15
<li> <a href=#installation>Installation</a>
 
16
<li> <a href=#examples>Examples</a>
 
17
<li> <a href=#reference>Reference</a>
 
18
</ul>
 
19
 
 
20
<a name=front_matter></a>
 
21
<h2>Front Matter</h2>
 
22
 
 
23
The FTP-Lite Library is copyright (C) 2004 Douglas Thain and the University of Notre Dame.
 
24
<p>
 
25
This product includes software developed by and/or derived from the Globus Project (http://www.globus.org/) to which the U.S. Government retains certain rights.
 
26
<p>
 
27
This program is released under the GNU General Public License. See the file COPYING for details.
 
28
<p>
 
29
This software comes with no warranty and no guarantee of support.
 
30
Questions, bug reports, and patches may be sent to
 
31
<a href=mailto:condor-admin@cs.wisc.edu>condor-admin@cs.wisc.edu</a>.
 
32
We will address such inquiries as time and resources permit.
 
33
 
 
34
<a name=introduction></a>
 
35
<h2>Introduction</h2>
 
36
 
 
37
FTP-Lite is a library for accessing FTP servers from UNIX C programs.
 
38
<p>
 
39
It is designed to be simple, correct, and easily debuggable.
 
40
In particular, FTP-Lite presents an FTP service in terms of UNIX abstractions.
 
41
Errors are return in standard <code>errno</code> values.
 
42
Data streams are presented as <code>FILE</code> objects.
 
43
All procedures perform blocking I/O.
 
44
<p>
 
45
The library may be built as-is in order to communicate with ordinary
 
46
name/password or anonymous FTP servers.  However, if the
 
47
<a href=http://www.globus.org>Globus Toolkit</a> is available, it will
 
48
also perform GSI authentication with your proxy certificate.
 
49
<p>
 
50
FTP-Lite provides perfectly reasonable performance for simple clients
 
51
that access one file at a time.  For clients that need to manage multiple
 
52
servers at once, we heartily recommend the FTP implementation found in the
 
53
Globus Toolkit. It uses a variety of techniques, such as
 
54
multiple data streams and non-blocking interfaces, for achieving high
 
55
performance and multi-server access.
 
56
<p>
 
57
This library was designed specifically to be used with the
 
58
<a href=http://www.cs.wisc.edu/condor/pfs>Pluggable File System</a>,
 
59
which presents network storage devices as UNIX file systems.
 
60
You are welcome to use it for other purposes, according to the terms
 
61
set out in the GNU Library General Public License.
 
62
 
 
63
<a name=installation></a>
 
64
<h2>Installation</h2>
 
65
 
 
66
Download the FTP-Lite source package from the
 
67
<a href=http://www.cs.wisc.edu/condor/ftp_lite>web page</a>.
 
68
Unpack the archive like so:
 
69
 
 
70
<dir>
 
71
<pre>
 
72
% gunzip ftp_lite-0.0.tar.gz
 
73
% tar xvf ftp_lite-0.0.tar
 
74
</pre>
 
75
</dir>
 
76
 
 
77
Decide on a place to install FTP-Lite.
 
78
If you have the Globus and SSL libraries, figure out where they are installed,
 
79
and feed the information to <code>configure</code>:
 
80
 
 
81
<dir>
 
82
<pre>
 
83
% cd ftp_lite-0.0
 
84
% ./configure --prefix /install/dir --with-globus-path /path/to/globus --with-ssl-path /path/to/ssl
 
85
</pre>
 
86
</dir>
 
87
 
 
88
(At UW-Madison, the appropriate invocation would be:)
 
89
 
 
90
<dir>
 
91
<pre>
 
92
% cd ftp_lite-0.0
 
93
% ./configure --prefix ~/ftp_lite --with-globus-path /p/condor/workspaces/globus --with-ssl-path /p/condor/workspaces/ssl
 
94
</pre>
 
95
</dir>
 
96
 
 
97
Finally, build and install the library:
 
98
 
 
99
<dir>
 
100
<pre>
 
101
% make
 
102
% make install
 
103
</pre>
 
104
</dir>
 
105
 
 
106
To build a program using FTP-Lite, change your compile and link options like so:
 
107
 
 
108
<dir>
 
109
<pre>
 
110
CCFLAGS += -I/install/dir/include
 
111
LDFLAGS += -L/install/dir/lib -lftp_lite
 
112
</pre>
 
113
</dir>
 
114
 
 
115
<a name=examples></a>
 
116
<h2>Examples</h2>
 
117
 
 
118
For examples of using the library, we recommend that you begin by examining the code for the simple programs <code>ftp_lite_test</code> and <code>ftp_lite_copy</code>.  A complete description of every function may be found in the <a href=#reference>reference</a> section below.  Here is a brief example to get you started.
 
119
<p>
 
120
A program using the library must first include <code>ftp_lite.h</code>:
 
121
<dir>
 
122
<pre>
 
123
#include "ftp_lite.h"
 
124
</pre>
 
125
</dir>
 
126
To open a server, call <code>ftp_lite_open</code> with a server name, port number, and a stream on which to send debugging messages.  For no debugging, leave the third argument null.  On success, this function returns a pointer to a server.
 
127
<dir>
 
128
<pre>
 
129
struct ftp_server *s;
 
130
 
 
131
s = ftp_lite_open( "ftp.cs.wisc.edu", FTP_LITE_DEFAULT_PORT, stderr );
 
132
if(!s) {
 
133
        perror("couldn't open server");
 
134
        return 0;
 
135
}
 
136
</pre>
 
137
</dir>
 
138
You must authenticate yourself to the server before accessing any data.  Three sorts of authentication are currently provided: anonymous, userpass, and Globus.  For example, to authenticate with a username and password:
 
139
<dir>
 
140
<pre>
 
141
success = ftp_lite_auth_userpass(server,"fred","secret");
 
142
if(!success) {
 
143
        perror("couldn't log in");
 
144
        return 0;
 
145
}
 
146
</pre>
 
147
</dir>
 
148
For convenience, FTP-Lite provides a single procedure which tries the various authentication methods, possible requesting information from the console.  Most users will find it easiest to replace the above two steps with :
 
149
<pre>
 
150
<dir>
 
151
s = ftp_lite_open_and_auth( "ftp.cs.wisc.edu", stderr );
 
152
if(!s) {
 
153
        perror("couldn't open server");
 
154
        return 0;
 
155
}
 
156
</pre>
 
157
</dir>
 
158
To retrieve a file, call <code>ftp_lite_get</code> with the server pointer, a path name, and the offset at which to begin.  On success, it returns a <code>FILE</code> object.
 
159
<dir>
 
160
<pre>
 
161
FILE *f;
 
162
 
 
163
f = ftp_lite_get( s, "README", 0 );
 
164
if(!f) {
 
165
        perror("couldn't get file");
 
166
        return 0;
 
167
}
 
168
</pre>
 
169
</dir>
 
170
You may read from this stream pointer using any of the standard UNIX I/O operations, such as <code>fscanf</code>, <code>fread</code>, and so on.  For convenience, FTP-Lite provides a function <code>ftp_lite_stream_to_stream</code> that will copy one whole file pointer into another.  So, to display this file, you might do this:
 
171
<dir>
 
172
<pre>
 
173
length = ftp_lite_stream_to_stream( f, stdout );
 
174
if(length<0) {
 
175
        perror("couldn't transfer data");
 
176
        return 0;
 
177
}
 
178
</pre>
 
179
</dir>
 
180
When done reading data, you must close the stream and inform the server that you are done:
 
181
<dir>
 
182
<pre>
 
183
fclose(f);
 
184
ftp_lite_done(s);
 
185
</pre>
 
186
</dir>
 
187
To close the connection to the server completely:
 
188
<dir>
 
189
<pre>
 
190
ftp_lite_close(s);
 
191
</pre>
 
192
</dir>
 
193
 
 
194
<a name=reference></a>
 
195
<h2>Reference</h2>
 
196
 
 
197
This section lists all of the public functions in the FTP-Lite library.
 
198
<p>
 
199
Unless noted otherwise, all functions return true (non-zero) on success or false (zero) on failure.  In addition, every function sets <code>errno</code> appropriately on a failure.  Tools for handling error values can be found in the UNIX man pages for <code>errno</code>, <code>strerror</code>, and <code>perror</code>.  Nearly every error value is a possible result of any function.
 
200
<p>
 
201
Some error values are inacurrate, due to weaknesses in the FTP protocol itself.  For example, the FTP error 550 is represented as the errno <code>EEXIST</code>.  However, a brief poll of servers shows that many return the same error value for errors that should be distinct, such as "no such file", and "file already exists."  So, be careful.
 
202
<p>
 
203
If the library is returning unexpected results, we recommend that you debug the code by passing <code>stderr</code> as the debugging argument to <code>ftp_lite_open</code>.  This will show a low of events in the protocol, and is invaluable in revealing unexpected events.
 
204
<p>
 
205
So, here are the procedures in the library:
 
206
<dir>
 
207
<li><b>ftp_lite_auth_anonymous</b><p>
 
208
<small>int ftp_lite_auth_anonymous( struct ftp_lite_server *s );</small><p>
 
209
Attempt to log in anonymously to an already-opened server.
 
210
<p>
 
211
<li><b>ftp_lite_auth_globus</b><p>
 
212
<small>int ftp_lite_auth_globus( struct ftp_lite_server *s );</small><p>
 
213
Attempt to log in with Globus credentials to an already-opened server.
 
214
The caller must have already established a proxy certificate with <code>grid-proxy-init</code> or a similar tool.
 
215
<p>
 
216
<li><b>ftp_lite_auth_userpass</b><p>
 
217
<small>int ftp_lite_auth_userpass( struct ftp_lite_server *s, const char *user, const char *password );</small><p>
 
218
Attempt to log in with this name and password.   This mechanism sends names and passwords in the clear and should be deprecated in favor of Globus authentication.
 
219
<p>
 
220
<li><b>ftp_lite_change_dir</b><p>
 
221
<small>int ftp_lite_change_dir( struct ftp_lite_server *s, const char *dir );</small><p>
 
222
Change the current working directory to that given.
 
223
<p>
 
224
<li><b>ftp_lite_close</b><p>
 
225
<small>void ftp_lite_close( struct ftp_lite_server *server );</small><p>
 
226
Close this open server.  Once a connection is closed, the server pointer is no longer valid.
 
227
<p>
 
228
<li><b>ftp_lite_delete int</b><p>
 
229
<small>int ftp_lite_delete( struct ftp_lite_server *s, const char *path );</small><p>
 
230
Delete a file.
 
231
<p>
 
232
<li><b>ftp_lite_delete_dir</b><p>
 
233
<small>int ftp_lite_delete_dir( struct ftp_lite_server *s, const char *dir );</small><p>
 
234
Delete a directory.  Most servers will not permit the deletion of a directory that is not empty.
 
235
<p>
 
236
<li><b>ftp_lite_done</b><p>
 
237
<small>int ftp_lite_done( struct ftp_lite_server *s );</small><p>
 
238
Signal that a data transfer is complete.  This must be called before any other functions are invoked.
 
239
<p>
 
240
<li><b>ftp_lite_get</b><p>
 
241
<small>FILE * ftp_lite_get( struct ftp_lite_server *s, const char *path, off_t offset );</small><p>
 
242
Retrieve a file beginning from this offset.  On success, returns a stream pointer.  On failure, returns null.  After reading to the end of the stream, you must call <code>fclose</code> and <code>ftp_lite_done</code>.
 
243
<p>
 
244
<li><b>ftp_lite_list</b><p>
 
245
<small>FILE * ftp_lite_list( struct ftp_lite_server *s, const char *path );</small><p>
 
246
Retrieve the list of names contained in this directory.  On success, return a stream pointer which will provide the list of newline-terminated names.  On failure, returns null.  After reading to the end of the stream, you must call <code>fclose</code> and <code>ftp_lite_done</code>.
 
247
<p>
 
248
<li><b>ftp_lite_login</b><p>
 
249
<small>int ftp_lite_login( const char *prompt, char *name, int namelen, char *pass, int passlen );</small><p>
 
250
Display a prompt on the console and ask the user to enter a name and password.  <code>name</code> and <code>pass</code> are filled in up to the lengths given.
 
251
<p>
 
252
<li><b>ftp_lite_make_dir</b><p>
 
253
<small>int ftp_lite_make_dir( struct ftp_lite_server *s, const char *dir );</small><p>
 
254
Create a directory.
 
255
<p>
 
256
<li><b>ftp_lite_nop</b><p>
 
257
<small>int ftp_lite_nop( struct ftp_lite_server *s );</small><p>
 
258
Send a no-operation command to the server.  This command is useful for determining if a connection is still alive.
 
259
<p>
 
260
<li><b>ftp_lite_open</b><p>
 
261
<small>struct ftp_lite_server * ftp_lite_open( const char *host, int port, FILE *log );</small><p>
 
262
Connect to a server on the given host and port.  The third argument gives a stream which is used for debugging information.  On success, return an opaque pointer to a server.  On failure, return null.  The appropriate port depends on the authentication method to be used.  For Globus authentication, connect to <code>FTP_LITE_GSS_DEFAULT_PORT</code>.  For anonymous and userpass authentication, connect to <code>FTP_LITE_DEFAULT_PORT</code>.
 
263
<p>
 
264
<li><b>ftp_lite_open_and_auth</b><p>
 
265
<small>struct ftp_lite_server * ftp_lite_open_and_auth( const char *host, FILE *log );</small><p>
 
266
Connect to a server, but try all available ports and authentication methods.  The second argument gives a stream to be used for debugging.  On success, return an opaque pointer to a server.  On failure, return null.
 
267
<p>
 
268
<li><b>ftp_lite_put</b><p>
 
269
<small>FILE * ftp_lite_put( struct ftp_lite_server *s, const char *path, off_t offset, size_t size );</small><p>
 
270
Transmit a file to a server.  On success, returns a stream to be written to.  On failure, returns null.  After writing all data to the stream, you must call <code>fclose</code> and <code>ftp_lite_done</code>.  <code>offset</code> controls the point at which writing will begin in the target file.  If <code>size</code> is <code>FTP_LITE_WHOLE_FILE</code>, then the target file will be truncated when the stream is closed.  A variety of FTP commands may be used to implement a put, and not all severs will support all combinations of <code>offset</code> and <code>size</code>.
 
271
<p>
 
272
<li><b>ftp_lite_rename</b><p>
 
273
<small>int ftp_lite_rename( struct ftp_lite_server *s, const char *oldname, const char *newname );</small><p>
 
274
Move the file <code>oldname</code> in <code>newname</code>.
 
275
<p>
 
276
<li><b>ftp_lite_size</b><p>
 
277
<small>size_t ftp_lite_size( struct ftp_lite_server *s, const char *path );</small><p>
 
278
Return the number of bytes stored in this file.  On failure, returns -1.
 
279
<p>
 
280
<li><b>ftp_lite_stream_to_buffer</b><p>
 
281
<small>int ftp_lite_stream_to_buffer( FILE *input, char **buffer );</small><p>
 
282
Copy the contents of this stream into a memory buffer.  On success, returns the number of bytes copied.  On failure, returns -1.  <code>input</code> must be a stream opened for reading, and <code>buffer</code> must be a pointer to an uninitialized <code>char *</code>.  Space for the buffer will be allocated with <code>malloc</code>.  The caller becomes responsible for freeing the buffer when done.
 
283
<p>
 
284
<li><b>ftp_lite_stream_to_stream</b><p>
 
285
<small>int ftp_lite_stream_to_stream( FILE *input, FILE *output );</small><p>
 
286
Copy the contents of one stream into another.  On success, returns the number of bytes copied.  On failure, returns -1.
 
287
<p>
 
288
<li><b>ftp_lite_third_party_transfer</b><p>
 
289
<small>int ftp_lite_third_party_transfer( struct ftp_lite_server *source, const char *source_file, struct ftp_lite_server *target, const char *target_file );</small><p>
 
290
Performs a third-party transfer between two servers.  Each server must already be opened and authenticated.  There are a large number of reasons for which a third party transfer might fail.  We recommend you use this feature with the debugging stream enabled.
 
291
<p>
 
292
</dir>
 
293
 
 
294
</body>
 
295