Advertisement
Guest User

Untitled

a guest
Jan 31st, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. <?php
  2. namespace FileTransfer;
  3.  
  4. abstract class ConnectionProtocol
  5. {
  6.  
  7. /*User login, String*/
  8. protected $user;
  9.  
  10. /*User pass, String*/
  11. protected $pass;
  12.  
  13. /*Hostname, String*/
  14. protected $host;
  15.  
  16. /*SSH port, String or Number*/
  17. protected $port;
  18.  
  19. /*current HostPath, String*/
  20. protected $connectionPath;
  21.  
  22. /*current localPath, String*/
  23. protected $localPath;
  24.  
  25. /*Connection, resource */
  26. protected $connection;
  27.  
  28. /*CallsStack, Array */
  29. protected $log;
  30.  
  31. /*LastResponse*/
  32. protected $response;
  33.  
  34. protected $lastError;
  35.  
  36. public function __construct( $user , $pwd, $host , $port, $localpath = __DIR__)
  37. {
  38. $this->user = $user;
  39. $this->pass = $pwd;
  40. $this->host = $host;
  41. $this->port = $port;
  42. $this->localPath = $localpath;
  43. $this->create();
  44. }
  45.  
  46. abstract protected function create();
  47.  
  48. public function __destruct( )
  49. {
  50. $this->close();
  51. }
  52. public function __toString()
  53. {
  54. return "<pre>".print_r($this->log, true)."</pre>";
  55. }
  56.  
  57. public function setLocalDir($path)
  58. {
  59. if ( file_exists($path) && is_dir($path))
  60. {
  61. $this->localPath = $path;
  62. return true;
  63. }
  64. else
  65. {
  66. $this->setError("Dir not exist");
  67. return false;
  68. }
  69. }
  70.  
  71. public function lastError()
  72. {
  73. return $this->lastError;
  74. }
  75.  
  76. protected function setError($error)
  77. {
  78. $this->lastError = $error;
  79. }
  80.  
  81. protected function addLog($str)
  82. {
  83. $this->log[] = $str;
  84. }
  85.  
  86. protected function pathBuilder($path)
  87. {
  88. if(stripos('/', $path) === 0) return $path;
  89. else return $this->connectionPath.'/'.$path ;
  90. }
  91.  
  92. }
  93.  
  94. interface transport{
  95. public function create();
  96. public function close();
  97. public function cd($args);
  98. public function download($args);
  99. public function upload($args);
  100. public function exec($args);
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement