Ik heb nu een sriptje om te kijken of een ftp server online is. Dat gaat goed behalve als het geen standaard poort (21) meer is.
Ik krijg dan deze error:
Warning: fputs(): supplied argument is not a valid stream resource in /home/vespa05/public_html/sF-fxpteam/images/lockdown/test.php on line 428
en deze ongeveer 300 keer:
Warning: fgets(): supplied argument is not a valid stream resource in /home/vespa05/public_html/sF-fxpteam/images/lockdown/test.php on line 438
De code is van een php class waar ik hier ongeveer 3 dagen geleden wat over vroeg.
De code is erg lang maar ik post hem hier tog maar.
/me Sorry dat het weer zo'n newbie foutje is
Ik krijg dan deze error:
Warning: fputs(): supplied argument is not a valid stream resource in /home/vespa05/public_html/sF-fxpteam/images/lockdown/test.php on line 428
en deze ongeveer 300 keer:
Warning: fgets(): supplied argument is not a valid stream resource in /home/vespa05/public_html/sF-fxpteam/images/lockdown/test.php on line 438
De code is van een php class waar ik hier ongeveer 3 dagen geleden wat over vroeg.
De code is erg lang maar ik post hem hier tog maar.
code:
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
| <?php
class ftp
{
/* Public variables */
var $debug;
var $umask;
var $timeout;
/* Private variables */
var $ftp_sock;
var $ftp_resp;
/* Constractor */
function ftp()
{
$this->debug = FALSE;
$this->umask = 0022;
$this->timeout = 30;
if (!defined("FTP_BINARY")) {
define("FTP_BINARY", 1);
}
if (!defined("FTP_ASCII")) {
define("FTP_ASCII", 0);
}
$this->ftp_resp = "";
}
/* Public functions */
function ftp_connect($server, $port)
{
$this->ftp_debug("Trying to ".$server.":".$port." ...\n");
$this->ftp_sock = @fsockopen($server, $port, $errno, $errstr, $this->timeout);
if (!$this->ftp_sock || !$this->ftp_ok()) {
$this->ftp_debug("Error : Cannot connect to remote host \"".$server.":".$port."\"\n");
$this->ftp_debug("Error : fsockopen() ".$errstr." (".$errno.")\n");
return FALSE;
}
$this->ftp_debug("Connected to remote host \"".$server.":".$port."\"\n");
return TRUE;
}
function ftp_login($user, $pass)
{
$this->ftp_putcmd("USER", $user);
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : USER command failed\n");
return FALSE;
}
$this->ftp_putcmd("PASS", $pass);
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : PASS command failed\n");
return FALSE;
}
$this->ftp_debug("Authentication succeeded\n");
return TRUE;
}
function ftp_pwd()
{
$this->ftp_putcmd("PWD");
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : PWD command failed\n");
return FALSE;
}
return ereg_replace("^[0-9]{3} \"(.+)\" .+\r\n", "\\1", $this->ftp_resp);
}
function ftp_size($pathname)
{
$this->ftp_putcmd("SIZE", $pathname);
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : SIZE command failed\n");
return -1;
}
return ereg_replace("^[0-9]{3} ([0-9]+)\r\n", "\\1", $this->ftp_resp);
}
function ftp_mdtm($pathname)
{
$this->ftp_putcmd("MDTM", $pathname);
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : MDTM command failed\n");
return -1;
}
$mdtm = ereg_replace("^[0-9]{3} ([0-9]+)\r\n", "\\1", $this->ftp_resp);
$date = sscanf($mdtm, "%4d%2d%2d%2d%2d%2d");
$timestamp = mktime($date[3], $date[4], $date[5], $date[1], $date[2], $date[0]);
return $timestamp;
}
function ftp_systype()
{
$this->ftp_putcmd("SYST");
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : SYST command failed\n");
return FALSE;
}
$DATA = explode(" ", $this->ftp_resp);
return $DATA[1];
}
function ftp_cdup()
{
$this->ftp_putcmd("CDUP");
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : CDUP command failed\n");
}
return $response;
}
function ftp_chdir($pathname)
{
$this->ftp_putcmd("CWD", $pathname);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : CWD command failed\n");
}
return $response;
}
function ftp_delete($pathname)
{
$this->ftp_putcmd("DELE", $pathname);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : DELE command failed\n");
}
return $response;
}
function ftp_rmdir($pathname)
{
$this->ftp_putcmd("RMD", $pathname);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : RMD command failed\n");
}
return $response;
}
function ftp_mkdir($pathname)
{
$this->ftp_putcmd("MKD", $pathname);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : MKD command failed\n");
}
return $response;
}
function ftp_file_exists($pathname)
{
if (!($remote_list = $this->ftp_nlist("-a"))) {
$this->ftp_debug("Error : Cannot get remote file list\n");
return -1;
}
reset($remote_list);
while (list(,$value) = each($remote_list)) {
if ($value == $pathname) {
$this->ftp_debug("Remote file ".$pathname." exists\n");
return 1;
}
}
$this->ftp_debug("Remote file ".$pathname." does not exist\n");
return 0;
}
function ftp_rename($from, $to)
{
$this->ftp_putcmd("RNFR", $from);
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : RNFR command failed\n");
return FALSE;
}
$this->ftp_putcmd("RNTO", $to);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : RNTO command failed\n");
}
return $response;
}
function ftp_nlist($arg = "", $pathname = "")
{
if (!($string = $this->ftp_pasv())) {
return FALSE;
}
if ($arg == "") {
$nlst = "NLST";
} else {
$nlst = "NLST ".$arg;
}
$this->ftp_putcmd($nlst, $pathname);
$sock_data = $this->ftp_open_data_connection($string);
if (!$sock_data || !$this->ftp_ok()) {
$this->ftp_debug("Error : Cannot connect to remote host\n");
$this->ftp_debug("Error : NLST command failed\n");
return FALSE;
}
$this->ftp_debug("Connected to remote host\n");
while (!feof($sock_data)) {
$list[] = ereg_replace("[\r\n]", "", fgets($sock_data, 512));
}
$this->ftp_close_data_connection($sock_data);
$this->ftp_debug(implode("\n", $list));
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : NLST command failed\n");
return FALSE;
}
return $list;
}
function ftp_rawlist($pathname = "")
{
if (!($string = $this->ftp_pasv())) {
return FALSE;
}
$this->ftp_putcmd("LIST", $pathname);
$sock_data = $this->ftp_open_data_connection($string);
if (!$sock_data || !$this->ftp_ok()) {
$this->ftp_debug("Error : Cannot connect to remote host\n");
$this->ftp_debug("Error : LIST command failed\n");
return FALSE;
}
$this->ftp_debug("Connected to remote host\n");
while (!feof($sock_data)) {
$list[] = ereg_replace("[\r\n]", "", fgets($sock_data, 512));
}
$this->ftp_debug(implode("\n", $list));
$this->ftp_close_data_connection($sock_data);
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : LIST command failed\n");
return FALSE;
}
return $list;
}
function ftp_get($localfile, $remotefile, $mode = 1)
{
umask($this->umask);
if (@file_exists($localfile)) {
$this->ftp_debug("Warning : local file will be overwritten\n");
}
$fp = @fopen($localfile, "w");
if (!$fp) {
$this->ftp_debug("Error : Cannot create \"".$localfile."\"");
$this->ftp_debug("Error : GET command failed\n");
return FALSE;
}
if (!$this->ftp_type($mode)) {
$this->ftp_debug("Error : GET command failed\n");
return FALSE;
}
if (!($string = $this->ftp_pasv())) {
$this->ftp_debug("Error : GET command failed\n");
return FALSE;
}
$this->ftp_putcmd("RETR", $remotefile);
$sock_data = $this->ftp_open_data_connection($string);
if (!$sock_data || !$this->ftp_ok()) {
$this->ftp_debug("Error : Cannot connect to remote host\n");
$this->ftp_debug("Error : GET command failed\n");
return FALSE;
}
$this->ftp_debug("Connected to remote host\n");
$this->ftp_debug("Retrieving remote file \"".$remotefile."\" to local file \"".$localfile."\"\n");
while (!feof($sock_data)) {
fputs($fp, fread($sock_data, 4096));
}
fclose($fp);
$this->ftp_close_data_connection($sock_data);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : GET command failed\n");
}
return $response;
}
function ftp_put($remotefile, $localfile, $mode = 1)
{
if (!@file_exists($localfile)) {
$this->ftp_debug("Error : No such file or directory \"".$localfile."\"\n");
$this->ftp_debug("Error : PUT command failed\n");
return FALSE;
}
$fp = @fopen($localfile, "r");
if (!$fp) {
$this->ftp_debug("Error : Cannot read file \"".$localfile."\"\n");
$this->ftp_debug("Error : PUT command failed\n");
return FALSE;
}
if (!$this->ftp_type($mode)) {
$this->ftp_debug("Error : PUT command failed\n");
return FALSE;
}
if (!($string = $this->ftp_pasv())) {
$this->ftp_debug("Error : PUT command failed\n");
return FALSE;
}
$this->ftp_putcmd("STOR", $remotefile);
$sock_data = $this->ftp_open_data_connection($string);
if (!$sock_data || !$this->ftp_ok()) {
$this->ftp_debug("Error : Cannot connect to remote host\n");
$this->ftp_debug("Error : PUT command failed\n");
return FALSE;
}
$this->ftp_debug("Connected to remote host\n");
$this->ftp_debug("Storing local file \"".$localfile."\" to remote file \"".$remotefile."\"\n");
while (!feof($fp)) {
fputs($sock_data, fread($fp, 4096));
}
fclose($fp);
$this->ftp_close_data_connection($sock_data);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : PUT command failed\n");
}
return $response;
}
function ftp_site($command)
{
$this->ftp_putcmd("SITE", $command);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : SITE command failed\n");
}
return $response;
}
function ftp_quit()
{
$this->ftp_putcmd("QUIT");
if (!$this->ftp_ok() || !fclose($this->ftp_sock)) {
$this->ftp_debug("Error : QUIT command failed\n");
return FALSE;
}
$this->ftp_debug("Disconnected from remote host\n");
return TRUE;
}
/* Private Functions */
function ftp_type($mode)
{
if ($mode) {
$type = "I"; //Binary mode
} else {
$type = "A"; //ASCII mode
}
$this->ftp_putcmd("TYPE", $type);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : TYPE command failed\n");
}
return $response;
}
function ftp_port($ip_port)
{
$this->ftp_putcmd("PORT", $ip_port);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : PORT command failed\n");
}
return $response;
}
function ftp_pasv()
{
$this->ftp_putcmd("PASV");
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : PASV command failed\n");
return FALSE;
}
$ip_port = ereg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*\r\n$", "\\1", $this->ftp_resp);
return $ip_port;
}
function ftp_putcmd($cmd, $arg = "")
{
if ($arg != "") {
$cmd = $cmd." ".$arg;
}
fputs($this->ftp_sock, $cmd."\r\n");
$this->ftp_debug("> ".$cmd."\n");
return TRUE;
}
function ftp_ok()
{
$this->ftp_resp = "";
do {
$res = fgets($this->ftp_sock, 512);
$this->ftp_resp .= $res;
} while (substr($res, 3, 1) != " ");
$this->ftp_debug(str_replace("\r\n", "\n", $this->ftp_resp));
if (!ereg("^[123]", $this->ftp_resp)) {
return FALSE;
}
return TRUE;
}
function ftp_close_data_connection($sock)
{
$this->ftp_debug("Disconnected from remote host\n");
return fclose($sock);
}
function ftp_open_data_connection($ip_port)
{
if (!ereg("[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+", $ip_port)) {
$this->ftp_debug("Error : Illegal ip-port format(".$ip_port.")\n");
return FALSE;
}
$DATA = explode(",", $ip_port);
$ipaddr = $DATA[0].".".$DATA[1].".".$DATA[2].".".$DATA[3];
$port = $DATA[4]*256 + $DATA[5];
$this->ftp_debug("Trying to ".$ipaddr.":".$port." ...\n");
$data_connection = @fsockopen($ipaddr, $port, $errno, $errstr);
if (!$data_connection) {
$this->ftp_debug("Error : Cannot open data connection to ".$ipaddr.":".$port."\n");
$this->ftp_debug("Error : ".$errstr." (".$errno.")\n");
return FALSE;
}
return $data_connection;
}
function ftp_debug($message = "")
{
if ($this->debug) {
echo $message;
}
return TRUE;
}
}
$hostencode = base64_decode($_GET[host]);
$ftp_host = "$hostencode";
$ftp_user = "$_GET[user]";
$ftp_pass = "$_GET[pass]";
$ftp_port = "$_GET[port]";
$ftp = new ftp();
if (!$ftp->ftp_connect($ftp_host, $ftp_port)) {
echo"offline";
}
if (!$ftp->ftp_login($ftp_user, $ftp_pass)) {
$ftp->ftp_quit();
echo"offline";
}
else {
echo"online";
}
$ftp->ftp_quit();
?> |
/me Sorry dat het weer zo'n newbie foutje is