Advertisement
Guest User

Untitled

a guest
May 23rd, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. $fp = fopen($path, 'r');
  2. $ftp_server = 'ftps://'.$server.'/'.$filename;
  3. $ch = curl_init();
  4. curl_setopt($ch, CURLOPT_URL, $ftp_server);
  5. curl_setopt($ch, CURLOPT_USERPWD,$user.':'.$pass);
  6. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  7. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  8. curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_TRY);
  9. curl_setopt($ch, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);
  10. curl_setopt($ch, CURLOPT_UPLOAD, 1);
  11. curl_setopt($ch, CURLOPT_INFILE, $fp);
  12.  
  13. $output = curl_exec($ch);
  14. $error_no = curl_errno($ch);
  15. //var_dump(curl_error($ch));
  16. curl_close($ch);
  17.  
  18. <?php
  19.  
  20. class ImplicitFtp {
  21.  
  22. private $server;
  23. private $username;
  24. private $password;
  25.  
  26. public function __construct($server, $username, $password) {
  27. $this->server = $server;
  28. $this->username = $username;
  29. $this->password = $password;
  30. }
  31.  
  32. public function download($remote, $local = null) {
  33. if ($local === null) {
  34. $local = tempnam('/tmp', 'implicit_ftp');
  35. }
  36.  
  37. if ($fp = fopen($local, 'w')) {
  38. $ftp_server = 'ftps://' . $this->server . '/' . $remote;
  39. $ch = curl_init();
  40.  
  41. curl_setopt($ch, CURLOPT_URL, $ftp_server);
  42. curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);
  43. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  44. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  45. curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_TRY);
  46. curl_setopt($ch, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);
  47. curl_setopt($ch, CURLOPT_UPLOAD, 0);
  48. curl_setopt($ch, CURLOPT_FILE, $fp);
  49.  
  50. curl_exec($ch);
  51.  
  52. if (curl_error($ch)) {
  53. curl_close($ch);
  54. return false;
  55. } else {
  56. curl_close($ch);
  57. return $local;
  58. }
  59. }
  60. return false;
  61. }
  62.  
  63. public function upload($local, $remote) {
  64. if ($fp = fopen($local, 'r')) {
  65. $ftp_server = 'ftps://' . $this->server . '/' . $remote;
  66. $ch = curl_init();
  67.  
  68. curl_setopt($ch, CURLOPT_URL, $ftp_server);
  69. curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);
  70. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  71. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  72. curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_TRY);
  73. curl_setopt($ch, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);
  74. curl_setopt($ch, CURLOPT_UPLOAD, 1);
  75. curl_setopt($ch, CURLOPT_INFILE, $fp);
  76.  
  77. curl_exec($ch);
  78. $err = curl_error($ch);
  79. curl_close($ch);
  80.  
  81. return !$err;
  82. }
  83. return false;
  84. }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement