Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. <?php
  2. function FtpCmd($handler, $command)
  3. {
  4. echo $command . "\n";
  5.  
  6. $ansver = ftp_raw($handler, $command);
  7.  
  8. foreach($ansver as $item){
  9. echo $item . "\n";
  10. }
  11.  
  12. return $ansver;
  13. }
  14.  
  15. function FtpDownload($handler, $controlIP, $controlPort, $fileName){
  16.  
  17. echo "Downloading ".$fileName." from ".$controlIP.":".$controlPort."\n";
  18.  
  19. $socket = fsockopen($controlIP, $controlPort);
  20.  
  21. FtpCmd($handler, "RETR ".$fileName);
  22.  
  23. $s = '';
  24. while (!feof($socket)) {
  25. $s .= fread($socket, 4096);
  26. }
  27. fclose($socket);
  28.  
  29. return $s;
  30. }
  31.  
  32. $host = 'app.listglobally.com';
  33. $user = 'cardis';
  34. $pass = '7x8OqPn6by7D';
  35. $passive = true;
  36. echo "Connecting..\n";
  37. $handler = ftp_connect($host, 21);
  38. if ($handler) {
  39. $res = ftp_login($handler, $user, $pass);
  40. if (!$res) {
  41. echo "Can not login\n";
  42. }
  43. else {
  44. FtpCmd($handler, 'OPTS UTF8 ON');
  45. FtpCmd($handler, 'CWD /data');
  46. FtpCmd($handler, 'TYPE A');
  47. $ret = FtpCmd($handler, 'PASV');
  48. if (preg_match('/^227.*\(([0-9]+,[0-9]+,[0-9]+,[0-9]+),([0-9]+),([0-9]+)\)/', $ret[0], $matches)) {
  49.  
  50. $controlIP = str_replace(',', '.', $matches[1]);
  51. $controlPort = intval($matches[2])*256+intval($matches[3]);
  52.  
  53. $text = FtpDownload($handler, $controlIP, $controlPort, "1.txt");
  54.  
  55. echo $text;
  56. }
  57.  
  58. }
  59. ftp_close($handler);
  60. }
  61. else {
  62. echo "Can not connect\n";
  63. }
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement