passive mode
[oftp] / src / ftp.h
1 #ifndef FTP_H_
2 #define FTP_H_
3
4 enum {FTP_DIR, FTP_FILE};       /* ftp_dirent type */
5
6 enum {
7         FTP_PWD,
8         FTP_CHDIR,
9         FTP_CDUP,
10         FTP_MKDIR,
11         FTP_RMDIR,
12         FTP_DEL,
13         FTP_LIST,
14         FTP_RETR,
15         FTP_STORE
16 };
17
18 enum {
19         FTP_DISC,
20         FTP_CONN_PASV,
21         FTP_CONN_ACT
22 };
23
24 enum {
25         FTP_REMOTE,
26         FTP_LOCAL
27 };
28
29 enum {
30         FTP_MOD_REMDIR  = 0x100,
31         FTP_MOD_LOCDIR  = 0x200
32 };
33
34 struct ftp_op {
35         int op;
36         char *arg;
37
38         struct ftp_op *next;
39 };
40
41 struct ftp_dirent {
42         char *name;
43         int type;
44         long size;
45 };
46
47 struct ftp {
48         int ctl, lis, data;     /* sockets */
49         int lis_port;
50
51         int status, busy;
52         char *user, *pass;
53         int passive;
54
55         struct ftp_op *qhead, *qtail;
56
57         int (*cproc)(struct ftp *ftp, int code, const char *buf, void *cls);
58         void (*dproc)(struct ftp *ftp, const char *buf, int sz, void *cls);
59         void *cproc_cls, *dproc_cls;
60
61         char crecv[256];
62         int num_crecv;
63         char drecv[256];
64
65         char *curdir[2];
66         struct ftp_dirent *dirent[2];           /* dynamic array */
67
68         int last_resp;
69         int modified;
70 };
71
72 struct ftp *ftp_alloc(void);
73 void ftp_free(struct ftp *ftp);
74
75 void ftp_auth(const char *user, const char *pass);
76
77 int ftp_connect(struct ftp *ftp, const char *host, int port);
78 void ftp_close(struct ftp *ftp);
79
80 int ftp_sockets(struct ftp *ftp, int *sockv, int maxsize);
81
82 int ftp_handle(struct ftp *ftp, int s);
83
84 int ftp_queue(struct ftp *ftp, int op, const char *arg);
85 int ftp_waitresp(struct ftp *ftp, time_t timeout);
86
87 int ftp_update(struct ftp *ftp);
88 int ftp_pwd(struct ftp *ftp);
89 int ftp_chdir(struct ftp *ftp, const char *dirname);
90 int ftp_mkdir(struct ftp *ftp, const char *dirname);
91 int ftp_rmdir(struct ftp *ftp, const char *dirname);
92 int ftp_delete(struct ftp *ftp, const char *fname);
93 int ftp_list(struct ftp *ftp);
94 int ftp_retrieve(struct ftp *ftp, const char *fname);
95 int ftp_store(struct ftp *ftp, const char *fname);
96
97 const char *ftp_curdir(struct ftp *ftp, int whichdir);
98 int ftp_num_dirent(struct ftp *ftp, int whichdir);
99 struct ftp_dirent *ftp_dirent(struct ftp *ftp, int whichdir, int idx);
100
101
102 #endif  /* FTP_H_ */