-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFtp.php
More file actions
111 lines (90 loc) · 2.08 KB
/
Copy pathFtp.php
File metadata and controls
111 lines (90 loc) · 2.08 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
<?php
/**
* Created by PhpStorm.
* User: colorrabbit
* Date: 2017/7/24
* Time: 下午4:39
*/
namespace ColorGallery;
class Ftp
{
/**
* @var $conn
*/
private $conn;
/**
* @return mixed
*/
public function getConn()
{
return $this->conn;
}
/**
* @param mixed $conn
*/
public function setConn($conn)
{
$this->conn = $conn;
}
public function ftpConnect($host, $port = '')
{
if (empty($port)) {
$this->conn = ftp_connect($host);
} else {
$this->conn = ftp_connect($host, $port);
}
if (!$this->conn) {
return 'login fail';
}
return 'login success';
}
public function ftpLogin($ftpUsername, $ftpPassword)
{
$loginResult = ftp_login($this->conn, $ftpUsername, $ftpPassword);
if (!$loginResult) {
return 'login fail';
}
ftp_pasv($this->conn, true);
return 'login success';
}
public function fptPwd()
{
$inDir = ftp_pwd($this->conn);
if (!$inDir) {
return 'get dir info fail';
}
return $inDir;
}
public function ftpList()
{
return ftp_nlist($this->conn, $this->fptPwd());
}
public function ftpMkdir($dir)
{
if (!in_array($this->conn . '/' . $dir, $this->ftpList())) {
if (!ftp_mkdir($this->conn, $dir)) {
return 'mkdir fail';
}
return 'mkdir ' . $dir . ' success';
}
return 'file exists';
}
public function fptChdir($dir)
{
if (!ftp_chdir($this->conn, $dir)) {
return 'chdir fail';
}
return 'chdir ' . $dir . 'success';
}
public function ftpPut($remoteFile, $file)
{
if (ftp_put($this->conn, $remoteFile, $file, FTP_ASCII)) {
return 'Successfully Uploadeed ' . $file;
}
return 'There was a problem while uploading ' . $file;
}
public function ftpClose()
{
ftp_close($this->conn);
}
}