forked from Andr3as/Codiad-CodeTransfer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.transfer.php
More file actions
executable file
·201 lines (185 loc) · 8.09 KB
/
class.transfer.php
File metadata and controls
executable file
·201 lines (185 loc) · 8.09 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
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
<?php
/*
* Copyright (c) Codiad & Andr3as, distributed
* as-is and without warranty under the MIT License.
* See [root]/license.md for more information. This information must remain intact.
*/
class transfer_controller {
static public function startConnection($host, $user, $pass, $port) {
if ($_SESSION['transfer_type'] == "ftp") {
$ftp = new ftp_client();
$ftp->startConnection($host, $user, $pass, $port);
} else {
$ssh2 = new scp_client();
$ssh2->startConnection($host, $user, $pass, $port);
}
}
static public function stopConnection() {
if ($_SESSION['transfer_type'] == "ftp") {
$ftp = new ftp_client();
$ftp->stopConnection();
} else {
$ssh2 = new scp_client();
$ssh2->stopConnection();
}
}
/////////////////////////////////////////////////////////////////////////
// Remote server index (Returns a list of files and directorys on the
// remote server as json) For more information: see parseRawList();
/////////////////////////////////////////////////////////////////////////
static public function getServerFiles($path) {
if ($_SESSION['transfer_type'] == "ftp") {
$ftp = new ftp_client();
return $ftp->getServerFiles($path);
} else {
$ssh2 = new scp_client();
return $ssh2->getServerFiles($path);
}
}
/////////////////////////////////////////////////////////////////////////
// Transfer a file to remote server
/////////////////////////////////////////////////////////////////////////
static public function transferFileToServer($cPath, $sPath, $fName, $mode) {
if ($_SESSION['transfer_type'] == "ftp") {
$ftp = new ftp_client();
return $ftp->transferFileToServer($cPath, $sPath, $fName, $mode);
} else {
$ssh2 = new scp_client();
return $ssh2->transferFileToServer($cPath, $sPath, $fName);
}
}
/////////////////////////////////////////////////////////////////////////
// Transfer a file to Codiad Server
/////////////////////////////////////////////////////////////////////////
static public function transferFileToClient($cPath, $sPath, $fName, $mode) {
if ($_SESSION['transfer_type'] == "ftp") {
$ftp = new ftp_client();
return $ftp->transferFileToClient($cPath, $sPath, $fName, $mode);
} else {
$ssh2 = new scp_client();
return $ssh2->transferFileToClient($cPath, $sPath, $fName);
}
}
/////////////////////////////////////////////////////////////////////////
// Create directory on remote server
/////////////////////////////////////////////////////////////////////////
static public function createServerDirectory($path) {
if ($_SESSION['transfer_type'] == "ftp") {
$ftp = new ftp_client();
return $ftp->createServerDirectory($path);
} else {
$ssh2 = new scp_client();
return $ssh2->createServerDirectory($path);
}
}
/////////////////////////////////////////////////////////////////////////
// Get current directory name
/////////////////////////////////////////////////////////////////////////
static public function getSeverDirectory() {
if ($_SESSION['transfer_type'] == "ftp") {
$ftp = new ftp_client();
return $ftp->getSeverDirectory();
} else {
$ssh2 = new scp_client();
return $ssh2->getSeverDirectory();
}
}
/////////////////////////////////////////////////////////////////////////
// Remove file on remote server
/////////////////////////////////////////////////////////////////////////
static public function removeServerFile($path) {
if ($_SESSION['transfer_type'] == "ftp") {
$ftp = new ftp_client();
return $ftp->removeServerFile($path);
} else {
$ssh2 = new scp_client();
return $ssh2->removeServerFile($path);
}
}
/////////////////////////////////////////////////////////////////////////
// Remove directory on remote server
/////////////////////////////////////////////////////////////////////////
static public function removeServerDirectory($path) {
if ($_SESSION['transfer_type'] == "ftp") {
$ftp = new ftp_client();
return $ftp->removeServerDirectory($path);
} else {
$ssh2 = new scp_client();
return $ssh2->removeServerDirectory($path);
}
}
/////////////////////////////////////////////////////////////////////////
// Change permissions of file on remote server
/////////////////////////////////////////////////////////////////////////
static public function changeServerFileMode($path, $mode) {
if ($_SESSION['transfer_type'] == "ftp") {
$ftp = new ftp_client();
return $ftp->changeServerFileMode($path, $mode);
} else {
$ssh2 = new scp_client();
return $ssh2->changeServerFileMode($path, $mode);
}
}
/////////////////////////////////////////////////////////////////////////
// Rename directory or file
/////////////////////////////////////////////////////////////////////////
static public function rename($path, $old, $new) {
if ($_SESSION['transfer_type'] == "ftp") {
$ftp = new ftp_client();
return $ftp->rename($path, $old, $new);
} else {
$ssh2 = new scp_client();
return $ssh2->rename($path, $old, $new);
}
}
/////////////////////////////////////////////////////////////////////////
// Rename directory or file
/////////////////////////////////////////////////////////////////////////
static public function changeServerGroup($path, $name) {
if ($_SESSION['transfer_type'] == "ftp") {
return '{"status":"error","message":"FTP: Impossible To Change Group"}';
} else {
$ssh2 = new scp_client();
return $ssh2->changeServerGroup($path, $name);
}
}
/////////////////////////////////////////////////////////////////////////
// Sort an array of a server index
/////////////////////////////////////////////////////////////////////////
static public function mySort($a, $b) {
$d = self::editString($a['fName']);
$e = self::editString($b['fName']);
$c = array($d, $e);
sort($c);
if ($d == $e) {
return 0;
}
if ($c[0] == $d) {
return -1;
} else {
return 1;
}
}
static public function editString($str) {
if (substr($str, 0, 1) == ".") {
$str = substr($str, 1);
}
return strtolower($str);
}
static public function getWorkspacePath($path) {
if (strpos($path, "/") === 0) {
//Unix absolute path
return $path;
}
if (strpos($path, ":/") !== false) {
//Windows absolute path
return $path;
}
if (strpos($path, ":\\") !== false) {
//Windows absolute path
return $path;
}
return "../../workspace/".$path;
}
}
?>