Advertisement
eappereira

FTP file transfer

Apr 30th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1.  
  2. $host = 'ftp.example.org';
  3. $usr = 'example_user';
  4. $pwd = 'example_password';
  5.  
  6. $local_file = './example.txt';
  7. $ftp_path = '/data/example.txt';
  8.  
  9. $conn_id = ftp_connect($host, 21) or die ("Cannot connect to host");
  10.  
  11.  
  12. ftp_login($conn_id, $usr, $pwd) or die("não foi possível conectar ao FTP");
  13.  
  14. $upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_ASCII);
  15.  
  16. print (!$upload) ? 'Erro no Upload' : 'Upload completo';
  17. print "\n";
  18.  
  19. if (!function_exists('ftp_chmod')) {
  20.    function ftp_chmod($ftp_stream, $mode, $filename){
  21.         return ftp_site($ftp_stream, sprintf('CHMOD %o %s', $mode, $filename));
  22.    }
  23. }
  24.  
  25. if (ftp_chmod($conn_id, 0666, $ftp_path) !== false) {
  26.     print $ftp_path . " chmoded successfully to 666\n";
  27. } else {
  28.     print "could not chmod $file\n";
  29. }
  30.  
  31. ftp_close($conn_id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement