Posted By

erraja_07 on 03/18/11


Tagged


Versions (?)

PHP FTP read and write


 / Published in: PHP
 

  1. function connectToFTP($file_name,$download_to,$new_name)
  2. {
  3. $conn_id = ftp_connect("ip_address_comes_here") or die('could not connect');
  4. $login_result = ftp_login($conn_id, 'ftpuser', 'FtpU$er');
  5.  
  6. $dir_path = '/NDE Test Folder/';
  7.  
  8. if ((!$conn_id) || (!$login_result)) {
  9. //echo "FTP connection has failed!";
  10. //exit;
  11. return false;
  12. } else {
  13. //echo 'connected'; die;
  14. // get the file
  15. $local = fopen($download_to,"w");
  16. $result = ftp_fget($conn_id, $local,$dir_path.$file_name."", FTP_BINARY);
  17.  
  18. ftp_chdir($conn_id, $dir_path);
  19.  
  20. //ftp_rename($conn_id,"oldname.txt","newname.txt");
  21. ftp_rename($conn_id,$file_name,$new_name);
  22.  
  23. // close the FTP stream
  24. ftp_close($conn_id);
  25.  
  26. //return true;
  27.  
  28. // check upload status
  29. if (!$result) {
  30. return false;
  31. } else {
  32. return true;
  33. }
  34.  
  35. }
  36. }
  37.  
  38. function renameFTPFile($old_file, $new_file)
  39. {
  40. $conn_id = ftp_connect("ip_address_comes_here") or die('could not connect');
  41. $login_result = ftp_login($conn_id, 'ftpuser', 'FtpU$er');
  42.  
  43. ftp_chdir($conn_id, '/NDETestFolder/');
  44. //ftp_rename($conn_id,"oldname.txt","newname.txt");
  45. ftp_rename($conn_id,"eusa_wall.gif","rajdya.gif");
  46.  
  47. ftp_close($conn_id);
  48.  
  49. return true;
  50. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: mariraj on March 18, 2011

good work

You need to login to post a comment.