1 |
ab11 |
1.1 |
// ftp.h |
2 |
|
|
// Copyright (C) 1992-1995 Gnanasekaran Swaminathan <gs4t@virginia.edu> |
3 |
|
|
// |
4 |
|
|
// Permission is granted to use at your own risk and distribute this software |
5 |
|
|
// in source and binary forms provided the above copyright |
6 |
|
|
// notice and this paragraph are preserved on all copies. |
7 |
|
|
// This software is provided "as is" with no express or implied warranty. |
8 |
|
|
// |
9 |
|
|
// Version: 17Oct95 1.10 |
10 |
|
|
|
11 |
|
|
#ifndef FTP_H |
12 |
|
|
#define FTP_H |
13 |
|
|
|
14 |
|
|
#include <protocol.h> |
15 |
|
|
#include <sys/param.h> |
16 |
|
|
|
17 |
|
|
class ftp: public protocol { |
18 |
|
|
public: |
19 |
|
|
enum reptype { |
20 |
|
|
rt_ascii_nonprint, |
21 |
|
|
rt_ascii_telnet, |
22 |
|
|
rt_ascii_asa, |
23 |
|
|
rt_ebcdic_nonprint, |
24 |
|
|
rt_ebcdic_telnet, |
25 |
|
|
rt_ebcdic_asa, |
26 |
|
|
rt_image, |
27 |
|
|
rt_local |
28 |
|
|
}; |
29 |
|
|
|
30 |
|
|
enum filestru { |
31 |
|
|
fs_file, |
32 |
|
|
fs_record, |
33 |
|
|
fs_page |
34 |
|
|
}; |
35 |
|
|
|
36 |
|
|
enum transmode { |
37 |
|
|
tm_stream, |
38 |
|
|
tm_block, |
39 |
|
|
tm_comp |
40 |
|
|
}; |
41 |
|
|
|
42 |
|
|
enum replycodea { |
43 |
|
|
rca_posprelim = '1', |
44 |
|
|
rca_poscomp = '2', |
45 |
|
|
rca_posinter = '3', |
46 |
|
|
rca_error = '4', |
47 |
|
|
rca_negtranscomp = '4', |
48 |
|
|
rca_negpermcomp = '5' |
49 |
|
|
}; |
50 |
|
|
|
51 |
|
|
enum replycodeb { |
52 |
|
|
rcb_syntax = '0', |
53 |
|
|
rcb_info = '1', |
54 |
|
|
rcb_conn = '2', |
55 |
|
|
rcb_auth = '3', |
56 |
|
|
rcb_unspec = '4', |
57 |
|
|
rcb_filesys = '5' |
58 |
|
|
}; |
59 |
|
|
|
60 |
|
|
class ftpbuf: public protocol::protocolbuf { |
61 |
|
|
// the following are used when this is used as a server |
62 |
|
|
char* usr; |
63 |
|
|
char* password; |
64 |
|
|
char* account; |
65 |
|
|
char cwd [MAXPATHLEN]; |
66 |
|
|
char parentdir [MAXPATHLEN]; |
67 |
|
|
ftp::filestru fs; |
68 |
|
|
ftp::transmode tm; |
69 |
|
|
sockinetaddr udata; // user will listen at this addr for data conn. |
70 |
|
|
int serverportno; |
71 |
|
|
char replycode [5]; |
72 |
|
|
|
73 |
|
|
ostream* o; |
74 |
|
|
|
75 |
|
|
ftp::replycodea send_cmd (const char* cmd, const char* arg=0); |
76 |
|
|
ftp::replycodea ftpdata (int portno, istream* i, ostream* out, |
77 |
|
|
const char* cmd, const char* arg=0); |
78 |
|
|
|
79 |
|
|
ftpbuf (ftpbuf&); |
80 |
|
|
ftpbuf& operator = (ftpbuf&); |
81 |
|
|
public: |
82 |
|
|
ftpbuf (ostream* out = 0); |
83 |
|
|
|
84 |
|
|
ftp::replycodea get_response (); |
85 |
|
|
const char* reply_code () const { return replycode; } |
86 |
|
|
|
87 |
|
|
ftp::replycodea help () { return send_cmd ("HELP"); } |
88 |
|
|
ftp::replycodea noop () { return send_cmd ("NOOP"); } |
89 |
|
|
ftp::replycodea quit () { return send_cmd ("QUIT"); } |
90 |
|
|
ftp::replycodea abort () { return send_cmd ("ABOR"); } |
91 |
|
|
ftp::replycodea user (const char* name) {return send_cmd ("USER", name);} |
92 |
|
|
ftp::replycodea passwd (const char* pw) {return send_cmd ("PASS", pw); } |
93 |
|
|
ftp::replycodea acct (const char* ac) {return send_cmd ("ACCT", ac);} |
94 |
|
|
ftp::replycodea cd (const char* dir); |
95 |
|
|
ftp::replycodea useraddr (sockinetaddr sa); |
96 |
|
|
ftp::replycodea useraddr (const char* host, int portno); |
97 |
|
|
ftp::replycodea server_port (int portno); |
98 |
|
|
ftp::replycodea rep_type (ftp::reptype rt); |
99 |
|
|
ftp::replycodea file_stru (ftp::filestru fs); |
100 |
|
|
ftp::replycodea trans_mode (ftp::transmode tm); |
101 |
|
|
|
102 |
|
|
// service commands |
103 |
|
|
ftp::replycodea getfile (const char* rpath, const char* lpath); |
104 |
|
|
ftp::replycodea list (const char* lpath=0, int justnames = 0); |
105 |
|
|
ftp::replycodea putfile (const char* lpath, const char* rpath); |
106 |
|
|
ftp::replycodea putfile (const char* lpath); |
107 |
|
|
ftp::replycodea append (const char* lpath, const char* rpath); |
108 |
|
|
ftp::replycodea allocate (int numbytes); |
109 |
|
|
ftp::replycodea restart (int marker); |
110 |
|
|
ftp::replycodea rename (const char* rpath, const char* newrpath); |
111 |
|
|
ftp::replycodea rmfile (const char* rpath); |
112 |
|
|
ftp::replycodea rmdir (const char* rpath); |
113 |
|
|
ftp::replycodea mkdir (const char* rpath); |
114 |
|
|
ftp::replycodea pwd () { return send_cmd ("PWD"); } |
115 |
|
|
ftp::replycodea system () { return send_cmd ("SYST"); } |
116 |
|
|
ftp::replycodea status () { return send_cmd ("STAT"); } |
117 |
|
|
|
118 |
|
|
virtual void serve_clients (int portno = -1); |
119 |
|
|
virtual const char* rfc_name () const { return "ftp"; } |
120 |
|
|
virtual const char* rfc_doc () const { return "rfc959"; } |
121 |
|
|
}; |
122 |
|
|
|
123 |
|
|
protected: |
124 |
|
|
ftp (): ios (0) {} |
125 |
|
|
|
126 |
|
|
public: |
127 |
|
|
ftp (ostream* out); |
128 |
|
|
~ftp () { delete ios::rdbuf (); ios::init (0); } |
129 |
|
|
|
130 |
|
|
|
131 |
|
|
ftpbuf* rdbuf () { return (ftpbuf*) protocol::rdbuf (); } |
132 |
|
|
ftpbuf* operator -> () { return rdbuf (); } |
133 |
|
|
}; |
134 |
|
|
|
135 |
|
|
#endif // !FTP_H |