nx_server_plugin_sdk 1.0 Server Plugin SDK

ftplib.h
1 /***************************************************************************
2 ftplib.h - description
3 -------------------
4 begin : Son Jul 27 2003
5 copyright : (C) 2013 by magnus kulke
6 email : mkulke@gmail.com
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU Lesser General Public License as *
13 * published by the Free Software Foundation; either version 2.1 of the *
14 * License, or (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 /***************************************************************************
19 * Note: ftplib, on which ftplibpp was originally based upon used to be *
20 * licensed as GPL 2.0 software, as of Jan. 26th 2013 its author Thomas *
21 * Pfau allowed the distribution of ftplib via LGPL. Thus the license of *
22 * ftplibpp changed as well. *
23 ***************************************************************************/
24
25 #ifndef FTPLIB_H
26 #define FTPLIB_H
27
28 #if defined(_WIN32)
29
30 #if BUILDING_DLL
31 # define DLLIMPORT __declspec (dllexport)
32 #else /* Not BUILDING_DLL */
33 # define DLLIMPORT __declspec (dllimport)
34 #endif /* Not BUILDING_DLL */
35
36 #include <winsock2.h>
37 #include <windows.h>
38 #include <time.h>
39
40 #define fseeko64 fseek
41 #define fopen64 fopen
42
43 #endif
44
45 #ifndef _WIN32
46 #include <unistd.h>
47 #include <sys/time.h>
48 #endif
49
50 #ifdef NOLFS
51 #define off64_t long
52 #endif
53
54 #if defined(__APPLE__)
55 #define off64_t __darwin_off_t
56 #define fseeko64 fseeko
57 #define fopen64 fopen
58 #endif
59
60 //SSL
61 typedef struct ssl_st SSL;
62 typedef struct ssl_ctx_st SSL_CTX;
63 typedef struct bio_st BIO;
64 typedef struct x509_st X509;
65
66 #include <sys/types.h>
67
68 #ifndef _FTPLIB_SSL_CLIENT_METHOD_
69 #define _FTPLIB_SSL_CLIENT_METHOD_ TLSv1_2_client_method
70 #endif
71
72 using namespace std;
73
74 //SSL
75 typedef struct ssl_st SSL;
76 typedef struct ssl_ctx_st SSL_CTX;
77 typedef struct bio_st BIO;
78 typedef struct x509_st X509;
79
84 typedef int (*FtpCallbackXfer)(off64_t xfered, void *arg);
85 typedef int (*FtpCallbackIdle)(void *arg);
86 typedef void (*FtpCallbackLog)(char *str, void* arg, bool out);
87 //SSL
88 typedef bool (*FtpCallbackCert)(void *arg, X509 *cert);
89
90 struct ftphandle {
91 char *cput,*cget;
92 int handle;
93 int cavail,cleft;
94 char *buf;
95 int dir;
96 ftphandle *ctrl;
97 int cmode;
98 struct timeval idletime;
99 FtpCallbackXfer xfercb;
100 FtpCallbackIdle idlecb;
101 FtpCallbackLog logcb;
102 void *cbarg;
103 off64_t xfered;
104 off64_t cbbytes;
105 off64_t xfered1;
106 char response[256];
107 //SSL
108 SSL* ssl;
109 SSL_CTX* ctx;
110 BIO* sbio;
111 int tlsctrl;
112 int tlsdata;
113 FtpCallbackCert certcb;
114
115 off64_t offset;
116 bool correctpasv;
117 };
118
119 #if defined(_WIN32)
120 class DLLIMPORT ftplib {
121 #else
122 class ftplib {
123 #endif
124 public:
125
126 enum accesstype
127 {
128 dir = 1,
129 dirverbose,
130 fileread,
131 filewrite,
132 filereadappend,
133 filewriteappend
134 };
135
136 enum transfermode
137 {
138 ascii = 'A',
139 image = 'I'
140 };
141
142 enum connmode
143 {
144 pasv = 1,
145 port
146 };
147
148 enum fxpmethod
149 {
150 defaultfxp = 0,
151 alternativefxp
152 };
153
154 enum dataencryption
155 {
156 unencrypted = 0,
157 secure
158 };
159
160 ftplib();
161 ~ftplib();
162 char* LastResponse();
163 int Connect(const char *host);
164 int Login(const char *user, const char *pass);
165 int Site(const char *cmd);
166 int Raw(const char *cmd);
167 int SysType(char *buf, int max);
168 int Mkdir(const char *path);
169 int Chdir(const char *path);
170 int Cdup();
171 int Rmdir(const char *path);
172 int Pwd(char *path, int max);
173 int Nlst(const char *outputfile, const char *path);
174 int Dir(const char *outputfile, const char *path);
175 int Size(const char *path, int *size, transfermode mode);
176 int ModDate(const char *path, char *dt, int max);
177 int Get(const char *outputfile, const char *path, transfermode mode, off64_t offset = 0);
178 int Put(const char *inputfile, const char *path, transfermode mode, off64_t offset = 0);
179 int Rename(const char *src, const char *dst);
180 int Delete(const char *path);
181 int Quit();
182 void SetCallbackIdleFunction(FtpCallbackIdle pointer);
183 void SetCallbackLogFunction(FtpCallbackLog pointer);
184 void SetCallbackXferFunction(FtpCallbackXfer pointer);
185 void SetCallbackArg(void *arg);
186 void SetCallbackBytes(off64_t bytes);
187 void SetCorrectPasv(bool b) { mp_ftphandle->correctpasv = b; };
188 void SetCallbackIdletime(int time);
189 void SetConnmode(connmode mode);
190 static int Fxp(ftplib* src, ftplib* dst, const char *pathSrc, const char *pathDst, transfermode mode, fxpmethod method);
191 ftphandle* RawOpen(const char *path, accesstype type, transfermode mode);
192 int RawClose(ftphandle* handle);
193 int RawWrite(void* buf, int len, ftphandle* handle);
194 int RawRead(void* buf, int max, ftphandle* handle);
195 int TestControlConnection();
196 // SSL
197 int SetDataEncryption(dataencryption enc);
198 int NegotiateEncryption();
199 void SetCallbackCertFunction(FtpCallbackCert pointer);
200
201 private:
202 ftphandle* mp_ftphandle;
203
204 int FtpXfer(const char *localfile, const char *path, ftphandle *nControl, accesstype type, transfermode mode);
205 int FtpOpenPasv(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd);
206 int FtpSendCmd(const char *cmd, char expresp, ftphandle *nControl);
207 int FtpAcceptConnection(ftphandle *nData, ftphandle *nControl);
208 int FtpOpenPort(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd);
209 int FtpRead(void *buf, int max, ftphandle *nData);
210 int FtpWrite(void *buf, int len, ftphandle *nData);
211 int FtpAccess(const char *path, accesstype type, transfermode mode, ftphandle *nControl, ftphandle **nData);
212 int FtpClose(ftphandle *nData);
213 int socket_wait(ftphandle *ctl);
214 int readline(char *buf,int max,ftphandle *ctl);
215 int writeline(char *buf, int len, ftphandle *nData);
216 int readresp(char c, ftphandle *nControl);
217 void sprint_rest(char *buf, off64_t offset);
218 void ClearHandle();
219 int CorrectPasvResponse(unsigned char *v);
220 };
221
222 #endif
std
Definition: to_string.h:49
ftphandle
Definition: ftplib.h:90
ftplib
Definition: ftplib.h:122