d588e5624d05ad3d5d98ffbbf90a1871b7f126aa
[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_MOD_DIR     = 0x100
26 };
27
28 struct ftp_op {
29         int op;
30         char *arg;
31
32         struct ftp_op *next;
33 };
34
35 struct ftp_dirent {
36         char *name;
37         int type;
38         long size;
39 };
40
41 struct ftp {
42         int ctl, lis, data;     /* sockets */
43         int lis_port;
44
45         int status, busy;
46         char *user, *pass;
47         int passive;
48
49         struct ftp_op *qhead, *qtail;
50
51         int (*cproc)(struct ftp *ftp, int code, const char *buf, void *cls);
52         void (*dproc)(struct ftp *ftp, const char *buf, int sz, void *cls);
53         void *cproc_cls, *dproc_cls;
54
55         char crecv[256];
56         int num_crecv;
57         char drecv[256];
58
59         char *curdir;
60         struct ftp_dirent *dirent;              /* dynamic array */
61
62         int last_resp;
63         int modified;
64 };
65
66 struct ftp *ftp_alloc(void);
67 void ftp_free(struct ftp *ftp);
68
69 void ftp_auth(const char *user, const char *pass);
70
71 int ftp_connect(struct ftp *ftp, const char *host, int port);
72 void ftp_close(struct ftp *ftp);
73
74 int ftp_sockets(struct ftp *ftp, int *sockv, int maxsize);
75
76 int ftp_handle(struct ftp *ftp, int s);
77
78 int ftp_queue(struct ftp *ftp, int op, const char *arg);
79 int ftp_waitresp(struct ftp *ftp, long timeout);
80
81 int ftp_update(struct ftp *ftp);
82 int ftp_pwd(struct ftp *ftp);
83 int ftp_chdir(struct ftp *ftp, const char *dirname);
84 int ftp_mkdir(struct ftp *ftp, const char *dirname);
85 int ftp_rmdir(struct ftp *ftp, const char *dirname);
86 int ftp_delete(struct ftp *ftp, const char *fname);
87 int ftp_list(struct ftp *ftp);
88 int ftp_retrieve(struct ftp *ftp, const char *fname);
89 int ftp_store(struct ftp *ftp, const char *fname);
90
91 const char *ftp_curdir(struct ftp *ftp);
92 int ftp_num_dirent(struct ftp *ftp);
93 struct ftp_dirent *ftp_dirent(struct ftp *ftp, int idx);
94
95 int ftp_direntcmp(const void *a, const void *b);
96
97 #endif  /* FTP_H_ */