-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathftp++.cpp
More file actions
129 lines (99 loc) · 3.28 KB
/
Copy pathftp++.cpp
File metadata and controls
129 lines (99 loc) · 3.28 KB
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
/*******************************************************************************
* FTP access library (ftplib C++ wrapper)
*
* © 2017, Sauron
******************************************************************************/
#include <iostream>
#include "ftp++.hpp"
#define BUFSIZE 1024
#define FTPLIB(call) \
if (0==call) \
throw Exception(getLastResponse());
using namespace ftp;
ConnectionBase::~ConnectionBase() {
FtpClose(conn);
}
/******************************************************************************/
Connection::Connection(const char * host) {
if (!FtpConnect(host, &conn))
throw ConnectException();
}
const char * Connection::getLastResponse() {
return FtpLastResponse(conn);
}
void Connection::setConnectionMode(Mode mode) {
FTPLIB(FtpOptions(FTPLIB_CONNMODE, mode, conn));
}
void Connection::login(const char * user, const char * password) {
FTPLIB(FtpLogin(user, password, conn));
}
std::string Connection::getSystemType() {
char buffer[BUFSIZE+1];
FTPLIB(FtpSysType(buffer, BUFSIZE, conn));
return buffer;
}
std::string Connection::getDirectory() {
char buffer[BUFSIZE+1];
FTPLIB(FtpPwd(buffer, BUFSIZE, conn));
return buffer;
}
void Connection::cd(const char * directory) {
FTPLIB(FtpChdir(directory, conn));
}
void Connection::cdup() {
FTPLIB(FtpCDUp(conn));
}
void Connection::getList(const char * filename, const char * path) {
FTPLIB(FtpNlst(filename, path, conn));
}
void Connection::getFullList(const char * filename, const char * path) {
FTPLIB(FtpDir(filename, path, conn));
}
void Connection::mkdir(const char * directory) {
FTPLIB(FtpMkdir(directory, conn));
}
void Connection::rmdir(const char * directory) {
FTPLIB(FtpRmdir(directory, conn));
}
void Connection::rename(const char * oldName, const char * newName) {
FTPLIB(FtpRename(oldName, newName, conn));
}
void Connection::unlink(const char * filename) {
FTPLIB(FtpDelete(filename, conn));
}
void Connection::get(const char * local, const char * remote, TransferMode mode) {
FTPLIB(FtpGet(local, remote, mode, conn));
}
void Connection::put(const char * local, const char * remote, TransferMode mode) {
FTPLIB(FtpPut(local, remote, mode, conn));
}
unsigned Connection::size(const char * path, TransferMode mode) {
unsigned result;
FTPLIB(FtpSize(path, &result, mode, conn));
return result;
}
std::string Connection::modDate(const char * path) {
char buffer[32];
FTPLIB(FtpModDate(path, buffer, sizeof(buffer)-1, conn));
return buffer;
}
void Connection::site(const char * command) {
FTPLIB(FtpSite(command, conn));
}
/******************************************************************************/
DataConnection::DataConnection(Connection &connection,
const char * path, Type type, TransferMode mode) {
if (0==FtpAccess(path, type, mode, connection.conn, &conn))
throw Exception(connection.getLastResponse());
}
ssize_t DataConnection::read(void * buffer, size_t length) {
return FtpRead(buffer, length, conn);
}
ssize_t DataConnection::write(void * buffer, size_t length) {
return FtpWrite(buffer, length, conn);
}
/******************************************************************************/
__attribute__((constructor))
static void initialize() {
FtpInit();
}