forked from mkulke/ftplibpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftplib.h
executable file
·210 lines (181 loc) · 5.98 KB
/
ftplib.h
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
/***************************************************************************
ftplib.h - description
-------------------
begin : Son Jul 27 2003
copyright : (C) 2013 by magnus kulke
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 2.1 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/
/***************************************************************************
* Note: ftplib, on which ftplibpp was originally based upon used to be *
* licensed as GPL 2.0 software, as of Jan. 26th 2013 its author Thomas *
* Pfau allowed the distribution of ftplib via LGPL. Thus the license of *
* ftplibpp changed aswell. *
***************************************************************************/
#ifndef FTPLIB_H
#define FTPLIB_H
#if defined(_WIN32)
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
#include <time.h>
#endif
#ifndef _WIN32
#include <unistd.h>
#include <sys/time.h>
#endif
#ifdef NOLFS
#define off64_t long
#endif
#if defined(__APPLE__)
#define off64_t __darwin_off_t
#define fseeko64 fseeko
#define fopen64 fopen
#endif
#ifndef NOSSL
#include <openssl/ssl.h>
#endif
#ifndef _FTPLIB_SSL_CLIENT_METHOD_
#define _FTPLIB_SSL_CLIENT_METHOD_ TLSv1_2_client_method
#endif//_FTPLIB_SSL_CLIENT_METHOD_
using namespace std;
/**
*@author mkulke
*/
typedef int (*FtpCallbackXfer)(off64_t xfered, void *arg);
typedef int (*FtpCallbackIdle)(void *arg);
typedef void (*FtpCallbackLog)(char *str, void* arg, bool out);
#ifndef NOSSL
typedef bool (*FtpCallbackCert)(void *arg, X509 *cert);
#endif
struct ftphandle {
char *cput,*cget;
int handle;
int cavail,cleft;
char *buf;
int dir;
ftphandle *ctrl;
int cmode;
struct timeval idletime;
FtpCallbackXfer xfercb;
FtpCallbackIdle idlecb;
FtpCallbackLog logcb;
void *cbarg;
off64_t xfered;
off64_t cbbytes;
off64_t xfered1;
char response[256];
#ifndef NOSSL
SSL* ssl;
SSL_CTX* ctx;
BIO* sbio;
int tlsctrl;
int tlsdata;
FtpCallbackCert certcb;
#endif
off64_t offset;
bool correctpasv;
};
#if defined(_WIN32)
class DLLIMPORT ftplib {
#else
class ftplib {
#endif
public:
enum accesstype
{
dir = 1,
dirverbose,
fileread,
filewrite,
filereadappend,
filewriteappend
};
enum transfermode
{
ascii = 'A',
image = 'I'
};
enum connmode
{
pasv = 1,
port
};
enum fxpmethod
{
defaultfxp = 0,
alternativefxp
};
enum dataencryption
{
unencrypted = 0,
secure
};
ftplib();
~ftplib();
char* LastResponse();
int Connect(const char *host);
int Login(const char *user, const char *pass);
int Site(const char *cmd);
int Raw(const char *cmd);
int SysType(char *buf, int max);
int Mkdir(const char *path);
int Chdir(const char *path);
int Cdup();
int Rmdir(const char *path);
int Pwd(char *path, int max);
int Nlst(const char *outputfile, const char *path);
int Dir(const char *outputfile, const char *path);
int Size(const char *path, int *size, transfermode mode);
int ModDate(const char *path, char *dt, int max);
int Get(const char *outputfile, const char *path, transfermode mode, off64_t offset = 0);
int Put(const char *inputfile, const char *path, transfermode mode, off64_t offset = 0);
int Rename(const char *src, const char *dst);
int Delete(const char *path);
#ifndef NOSSL
int SetDataEncryption(dataencryption enc);
int NegotiateEncryption();
void SetCallbackCertFunction(FtpCallbackCert pointer);
#endif
int Quit();
void SetCallbackIdleFunction(FtpCallbackIdle pointer);
void SetCallbackLogFunction(FtpCallbackLog pointer);
void SetCallbackXferFunction(FtpCallbackXfer pointer);
void SetCallbackArg(void *arg);
void SetCallbackBytes(off64_t bytes);
void SetCorrectPasv(bool b) { mp_ftphandle->correctpasv = b; };
void SetCallbackIdletime(int time);
void SetConnmode(connmode mode);
static int Fxp(ftplib* src, ftplib* dst, const char *pathSrc, const char *pathDst, transfermode mode, fxpmethod method);
ftphandle* RawOpen(const char *path, accesstype type, transfermode mode);
int RawClose(ftphandle* handle);
int RawWrite(void* buf, int len, ftphandle* handle);
int RawRead(void* buf, int max, ftphandle* handle);
private:
ftphandle* mp_ftphandle;
int FtpXfer(const char *localfile, const char *path, ftphandle *nControl, accesstype type, transfermode mode);
int FtpOpenPasv(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd);
int FtpSendCmd(const char *cmd, char expresp, ftphandle *nControl);
int FtpAcceptConnection(ftphandle *nData, ftphandle *nControl);
int FtpOpenPort(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd);
int FtpRead(void *buf, int max, ftphandle *nData);
int FtpWrite(void *buf, int len, ftphandle *nData);
int FtpAccess(const char *path, accesstype type, transfermode mode, ftphandle *nControl, ftphandle **nData);
int FtpClose(ftphandle *nData);
int socket_wait(ftphandle *ctl);
int readline(char *buf,int max,ftphandle *ctl);
int writeline(char *buf, int len, ftphandle *nData);
int readresp(char c, ftphandle *nControl);
void ClearHandle();
int CorrectPasvResponse(unsigned char *v);
};
#endif