1
|
|
|
<?php |
2
|
|
|
namespace FMUP; |
3
|
|
|
|
4
|
|
|
use FMUP\Ftp\Factory; |
5
|
|
|
|
6
|
|
|
class Ftp |
7
|
|
|
{ |
8
|
|
|
const DRIVER = 'driver'; |
9
|
|
|
protected $driver; |
10
|
|
|
protected $params = array(); |
11
|
|
|
private $driverInstance = null; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var Factory |
15
|
|
|
*/ |
16
|
|
|
private $factory; |
17
|
|
|
|
18
|
9 |
|
public function __construct($params = array()) |
19
|
|
|
{ |
20
|
9 |
|
$this->driver = isset($params[self::DRIVER]) ? $params[self::DRIVER] : Factory::DRIVER_FTP; |
21
|
9 |
|
$this->params = $params; |
22
|
9 |
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return Ftp\FtpInterface |
26
|
|
|
* @throws Ftp\Exception |
27
|
|
|
*/ |
28
|
1 |
|
public function getDriver() |
29
|
|
|
{ |
30
|
1 |
|
if (!is_null($this->driverInstance)) { |
31
|
1 |
|
return $this->driverInstance; |
32
|
|
|
} |
33
|
|
|
|
34
|
1 |
|
$driverInstance = $this->getFactory()->create($this->driver, $this->params); |
35
|
1 |
|
$this->driverInstance = $driverInstance; |
36
|
1 |
|
return $this->driverInstance; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return Factory |
41
|
|
|
*/ |
42
|
2 |
|
public function getFactory() |
43
|
|
|
{ |
44
|
2 |
|
if (!$this->factory) { |
45
|
2 |
|
$this->factory = Factory::getInstance(); |
46
|
2 |
|
} |
47
|
2 |
|
return $this->factory; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param Factory $factory |
52
|
|
|
* @return $this |
53
|
|
|
*/ |
54
|
1 |
|
public function setFactory(Factory $factory) |
55
|
|
|
{ |
56
|
1 |
|
$this->factory = $factory; |
57
|
1 |
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $host |
62
|
|
|
* @param int $port |
63
|
|
|
* @return $this |
64
|
|
|
*/ |
65
|
1 |
|
public function connect($host, $port = 21) |
66
|
|
|
{ |
67
|
1 |
|
$this->getDriver()->connect($host, $port); |
68
|
1 |
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string $user |
73
|
|
|
* @param string $pass |
74
|
|
|
* @return bool |
75
|
|
|
*/ |
76
|
1 |
|
public function login($user, $pass) |
77
|
|
|
{ |
78
|
1 |
|
return $this->getDriver()->login($user, $pass); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $localFile |
83
|
|
|
* @param string $remoteFile |
84
|
|
|
* @return bool |
85
|
|
|
*/ |
86
|
1 |
|
public function get($localFile, $remoteFile) |
87
|
|
|
{ |
88
|
1 |
|
return $this->getDriver()->get($localFile, $remoteFile); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string $remoteFile |
93
|
|
|
* @param string $localFile |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
1 |
|
public function put($remoteFile, $localFile) |
97
|
|
|
{ |
98
|
1 |
|
return $this->getDriver()->put($remoteFile, $localFile); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param $file |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
1 |
|
public function delete($file) |
106
|
|
|
{ |
107
|
1 |
|
return $this->getDriver()->delete($file); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return bool |
112
|
|
|
*/ |
113
|
1 |
|
public function close() |
114
|
|
|
{ |
115
|
1 |
|
return $this->getDriver()->close(); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|