File: ftp.h

package info (click to toggle)
yafc 1.1.1.dfsg.1-4
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,248 kB
  • ctags: 1,679
  • sloc: ansic: 19,338; sh: 10,365; makefile: 155; perl: 38; ruby: 33
file content (292 lines) | stat: -rw-r--r-- 8,026 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/* $Id: ftp.h,v 1.15 2004/05/20 11:10:52 mhe Exp $
 *
 * ftp.h -- lower level FTP stuff
 *
 * Yet Another FTP Client
 * Copyright (C) 1998-2001, Martin Hedenfalk <mhe@stacken.kth.se>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. See COPYING for more details.
 */

#ifndef _ftp_h_included
#define _ftp_h_included

#include "syshdr.h"

#include "host.h"
#include "socket.h"
#include "url.h"
#include "linklist.h"
#include "rdirectory.h"
#include "rfile.h"
#include "ftpsigs.h"
#include "rglob.h"
#include "args.h"

#define MAXREPLY 512      /* max size of (one line of) reply string */

#define FTP_BUFSIZ 4096

#define ALARM_SEC 0
#define ALARM_USEC 500000

typedef enum {
	putNormal,
	putAppend,
	putUnique,
	putResume
} putmode_t;

typedef enum {
	getNormal,
	getAppend,
	getResume,
	getPipe
} getmode_t;

typedef enum {
	fxpNormal,
	fxpAppend,
	fxpUnique,
	fxpResume
} fxpmode_t;

typedef enum {       /* reply codes */
	ctNone,          /* no reply, (eg connection lost) */
	ctPrelim,        /* OK, gimme' more input */
	ctComplete,      /* OK, command completed */
	ctContinue,      /* OK, send next command in sequence (eg RNFR, RNTO) */
	ctTransient,     /* error, try later */
	ctError          /* unrecoverable error, don't try this again */
} code_t;

typedef enum {    /* verbosity levels */
	vbUnset,      /* undefined, used internally */
	vbNone,       /* never print anything */
	vbError,      /* only print errors (code >= 400) without code */
	vbCommand,    /* print all replies w/o code */
	vbDebug       /* always print everything, including sent commands */
} verbose_t;

typedef enum {
	tmAscii,      /* use ascii mode conversion */
	tmBinary,     /* no conversion, raw binary */
	tmCurrent     /* use current mode (ftp->prev_mode) */
} transfer_mode_t;

typedef enum {
	ltUnknown,
	ltUnix,
	ltDos,
	ltEplf,
	ltMlsd
} LIST_t;

typedef enum {
	mechNone,
	mechKrb4,
	mechKrb5,
	mechSSL
} mech_type_t;

typedef struct transfer_info
{
	char *remote_name;           /* name of remote file or 0 */
	char *local_name;            /* name of local file or 0 */
	long long total_size;             /* total size in bytes or -1 */
	long long size;                   /* size in bytes transferred so far */
	long long restart_size;           /* restart size */
	struct timeval start_time;   /* time of transfer start */
	bool interrupted;            /* true if transfer interrupted (w/SIGINT) */
	bool ioerror;                /* true if I/O error occurred */
	unsigned stalled;            /* incremented when stalled (no I/O) */
	unsigned barelfs;            /* number of bare LF's received (ascii) */
	bool transfer_is_put;        /* true if transfer is put (upload) */
	bool finished;               /* set when transfer finished */
	bool begin;
} transfer_info;

typedef void (*ftp_transfer_func)(transfer_info *ti);

typedef struct Ftp
{
	Socket *ctrl, *data;
	Host *host;
	url_t *url;

	list *cache;             /* list of rdirectory */
	list *dirs_to_flush;     /* list of (char *) */

	pid_t ssh_pid;           /* process id of ssh program, or 0 if
							  * ssh is not in use */
	args_t *ssh_args;
	int ssh_in, ssh_out;     /* file descriptors for use by ssh */
	int ssh_version;
	unsigned int ssh_id;
	int ssh_last_status;

	char reply[MAXREPLY+1];  /* last reply string from server */

	code_t code;  /* last reply code (1-5) */
	int fullcode; /* last reply code (XYZ) */

	/* ftp_read_reply() will timeout in this many seconds
	 * calls ftp_close() and jumps to restart_jmp on timeout
	 */
	unsigned int reply_timeout; /* 0 == no timeout */
	unsigned int open_timeout;

	bool connected;
	bool loggedin;
	verbose_t verbosity, tmp_verbosity;

	bool has_mdtm_command;
	bool has_size_command;
	bool has_pasv_command;
	bool has_stou_command;
	bool has_site_chmod_command;
	bool has_site_idle_command;
	bool has_mlsd_command;

	long restart_offset;  /* next transfer will be restarted at this offset */

	char *homedir;  /* home directory (curdir on startup) */
	char *curdir;   /* current directory */
	char *prevdir;  /* previous directory */

	list *taglist;  /* list of rfile */

	transfer_mode_t prev_type; /* previous data transfer type */

	LIST_t LIST_type;

	/* these functions should return a malloc()'d string or 0
	 * and print the prompt, returned string is free()'d
	 */
	char * (*getuser_hook)(const char *prompt);
	char * (*getpass_hook)(const char *prompt);

#ifdef SECFTP
	bool sec_complete;
	enum protection_level data_prot;
	enum protection_level command_prot;
	size_t buffer_size;
	void *app_data;

	struct buffer in_buffer, out_buffer;
	int request_data_prot;

	struct sec_client_mech *mech;
#endif

	char *last_mkpath; /* used to speed up ftp_mkpath() */

	transfer_info ti;

} Ftp;

extern Ftp *ftp;

void ftp_vtrace(const char *fmt, va_list ap);
void ftp_trace(const char *fmt, ...);
void ftp_err(const char *fmt, ...);

Ftp *ftp_create(void);
void ftp_destroy(Ftp *ftp);
void ftp_use(Ftp *ftp);
void ftp_reset_vars(void);
int ftp_set_trace(const char *filename);

void ftp_reply_timeout(unsigned int secs);
int ftp_cmd(const char *cmd, ...);
int ftp_open(const char *host);
int ftp_reopen(void);
int ftp_open_host(Host *hostp);
int ftp_open_url(url_t *urlp, bool reset_vars);
int ftp_login(const char *guessed_username, const char *anonpass);

void ftp_close();
void ftp_quit();
void ftp_quit_all(void);

int ftp_read_reply();
const char *ftp_getreply(bool withcode);

int ftp_list(const char *cmd, const char *param, FILE *fp);
int ftp_receive(const char *path, FILE *fp,
				transfer_mode_t mode, ftp_transfer_func hookf);
int ftp_getfile(const char *infile, const char *outfile, getmode_t how,
				transfer_mode_t mode, ftp_transfer_func hookf);
int ftp_putfile(const char *infile, const char *outfile, putmode_t how,
				transfer_mode_t mode, ftp_transfer_func hookf);
int ftp_fxpfile(Ftp *srcftp, const char *srcfile,
				Ftp *destftp, const char *destfile,
				fxpmode_t how, transfer_mode_t mode);

int ftp_reset();
void reset_transfer_info(void);
void transfer_finished(void);

int ftp_get_verbosity(void);
void ftp_set_verbosity(int verbosity);
void ftp_set_tmp_verbosity(int verbosity);
int get_username(url_t *url, const char *guessed_username, bool isproxy);

bool ftp_connected(void);
bool ftp_loggedin(void);

rdirectory *ftp_get_directory(const char *path);
rdirectory *ftp_read_directory(const char *path);
rdirectory *ftp_cache_get_directory(const char *path);
rfile *ftp_cache_get_file(const char *path);
rfile *ftp_get_file(const char *path);
void ftp_cache_list_contents(void);
void ftp_cache_flush_mark(const char *p);
void ftp_cache_flush_mark_for(const char *p);
void ftp_cache_flush(void);
void ftp_cache_clear(void);

char *ftp_getcurdir(void);
void ftp_update_curdir_x(const char *p);

int ftp_chdir(const char *path);
int ftp_mkdir(const char *path);
int ftp_mkpath(const char *path);
int ftp_rmdir(const char *path);
int ftp_rename(const char *oldname, const char *newname);
int ftp_cdup(void);
int ftp_unlink(const char *path);
int ftp_chmod(const char *path, const char *mode);
time_t ftp_filetime(const char *filename);
unsigned long long ftp_filesize(const char *path);
int ftp_idle(const char *idletime);
int ftp_noop(void);
int ftp_help(const char *arg);
int ftp_set_protlevel(const char *protlevel);
char *ftp_path_absolute(const char *path);
void ftp_flush_reply(void);
int ftp_type(transfer_mode_t type);
time_t gmt_mktime(const struct tm *ts);

/* returns:
 * 0 == is not a directory
 * 1 == is a real directory
 * 2 == is a link not in cache, maybe dir
 */
int ftp_maybe_isdir(rfile *fp);
void ftp_pwd(void);
char *perm2string(int perm);
void ftp_get_feat(void);

/* in lscolors.h */
void init_colors(void);



void connect_to_server(char **args, int *in, int *out, pid_t *sshpid);
char ** make_ssh_args(char ***args, char *add_arg);

#endif