| @@ 237-277 (lines=41) @@ | ||
| 234 | $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); |
|
| 235 | } |
|
| 236 | ||
| 237 | function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]') |
|
| 238 | { |
|
| 239 | if (substr($ftp_server, 0, 6) == 'ftp://') |
|
| 240 | $ftp_server = substr($ftp_server, 6); |
|
| 241 | elseif (substr($ftp_server, 0, 7) == 'ftps://') |
|
| 242 | $ftp_server = 'ssl://' . substr($ftp_server, 7); |
|
| 243 | if (substr($ftp_server, 0, 7) == 'http://') |
|
| 244 | $ftp_server = substr($ftp_server, 7); |
|
| 245 | $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => '')); |
|
| 246 | ||
| 247 | // Connect to the FTP server. |
|
| 248 | $this->connection = @fsockopen($ftp_server, $ftp_port, $err, $err, 5); |
|
| 249 | if (!$this->connection) |
|
| 250 | { |
|
| 251 | $this->error = 'bad_server'; |
|
| 252 | return; |
|
| 253 | } |
|
| 254 | ||
| 255 | // Get the welcome message... |
|
| 256 | if (!$this->check_response(220)) |
|
| 257 | { |
|
| 258 | $this->error = 'bad_response'; |
|
| 259 | return; |
|
| 260 | } |
|
| 261 | ||
| 262 | // Send the username, it should ask for a password. |
|
| 263 | fwrite($this->connection, 'USER ' . $ftp_user . "\r\n"); |
|
| 264 | if (!$this->check_response(331)) |
|
| 265 | { |
|
| 266 | $this->error = 'bad_username'; |
|
| 267 | return; |
|
| 268 | } |
|
| 269 | ||
| 270 | // Now send the password... and hope it goes okay. |
|
| 271 | fwrite($this->connection, 'PASS ' . $ftp_pass . "\r\n"); |
|
| 272 | if (!$this->check_response(230)) |
|
| 273 | { |
|
| 274 | $this->error = 'bad_password'; |
|
| 275 | return; |
|
| 276 | } |
|
| 277 | } |
|
| 278 | ||
| 279 | function chdir($ftp_path) |
|
| 280 | { |
|
| @@ 1674-1714 (lines=41) @@ | ||
| 1671 | $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); |
|
| 1672 | } |
|
| 1673 | ||
| 1674 | function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]') |
|
| 1675 | { |
|
| 1676 | if (substr($ftp_server, 0, 6) == 'ftp://') |
|
| 1677 | $ftp_server = substr($ftp_server, 6); |
|
| 1678 | elseif (substr($ftp_server, 0, 7) == 'ftps://') |
|
| 1679 | $ftp_server = 'ssl://' . substr($ftp_server, 7); |
|
| 1680 | if (substr($ftp_server, 0, 7) == 'http://') |
|
| 1681 | $ftp_server = substr($ftp_server, 7); |
|
| 1682 | $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => '')); |
|
| 1683 | ||
| 1684 | // Connect to the FTP server. |
|
| 1685 | $this->connection = @fsockopen($ftp_server, $ftp_port, $err, $err, 5); |
|
| 1686 | if (!$this->connection) |
|
| 1687 | { |
|
| 1688 | $this->error = 'bad_server'; |
|
| 1689 | return; |
|
| 1690 | } |
|
| 1691 | ||
| 1692 | // Get the welcome message... |
|
| 1693 | if (!$this->check_response(220)) |
|
| 1694 | { |
|
| 1695 | $this->error = 'bad_response'; |
|
| 1696 | return; |
|
| 1697 | } |
|
| 1698 | ||
| 1699 | // Send the username, it should ask for a password. |
|
| 1700 | fwrite($this->connection, 'USER ' . $ftp_user . "\r\n"); |
|
| 1701 | if (!$this->check_response(331)) |
|
| 1702 | { |
|
| 1703 | $this->error = 'bad_username'; |
|
| 1704 | return; |
|
| 1705 | } |
|
| 1706 | ||
| 1707 | // Now send the password... and hope it goes okay. |
|
| 1708 | fwrite($this->connection, 'PASS ' . $ftp_pass . "\r\n"); |
|
| 1709 | if (!$this->check_response(230)) |
|
| 1710 | { |
|
| 1711 | $this->error = 'bad_password'; |
|
| 1712 | return; |
|
| 1713 | } |
|
| 1714 | } |
|
| 1715 | ||
| 1716 | function chdir($ftp_path) |
|
| 1717 | { |
|