Advertisement
Guest User

Untitled

a guest
May 30th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. <?php
  2.  
  3. if($_GET['q'] == 'ftp_connect')
  4. {
  5. $connection = new connect_to_ftp;
  6. echo $connection->ftp_connection();
  7.  
  8. }
  9. elseif($_GET['q'] == 'get_connection_id')
  10. {
  11. $connection = new connect_to_ftp;
  12. echo $connection->get_connection();
  13. }
  14.  
  15.  
  16. class connect_to_ftp
  17. {
  18. public $ftp_server = "";
  19. public $username = "";
  20. public $password = "";
  21. public $connectionID, $login_result, $response;
  22.  
  23. public function ftp_connection()
  24. {
  25. $this->connectionID = ftp_connect($this->ftp_server);
  26.  
  27. if($this->connectionID==true)
  28. {
  29. $this->response = array("connection_error" => "Connected to ".$this->ftp_server);
  30. $this->login_result = ftp_login($this->connectionID, $this->username, $this->password);
  31.  
  32. if($this->login_result==true)
  33. {
  34. $this->response = array("connection_error" => "Login successful to ".$this->ftp_server);
  35. }else
  36. {
  37. $this->response = array("connection_error" => "Failed to login to ".$this->ftp_server." Check username and password");
  38. }
  39.  
  40. }else
  41. {
  42. $this->response = array("connection_error" => "Could not connect to ".$this->ftp_server);
  43. }
  44.  
  45. return json_encode($this->response);
  46. }
  47.  
  48. public function get_connection()
  49. {
  50. return $this->connectionID;
  51. }
  52. }
  53.  
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement