Return to Snippet

Revision: 43160
at March 18, 2011 02:17 by erraja_07


Updated Code
function connectToFTP($file_name,$download_to,$new_name)
	{	
		$conn_id = ftp_connect("ip_address_comes_here") or die('could not connect');
		$login_result = ftp_login($conn_id, 'ftpuser', 'FtpU$er');
		
		$dir_path = '/NDE Test Folder/';
		
		if ((!$conn_id) || (!$login_result)) {
			//echo "FTP connection has failed!";
			//exit;
			return false;
		} else {
			//echo 'connected'; die;
			// get the file
			$local = fopen($download_to,"w");
			$result = ftp_fget($conn_id, $local,$dir_path.$file_name."", FTP_BINARY);
			
			ftp_chdir($conn_id, $dir_path);
			
			//ftp_rename($conn_id,"oldname.txt","newname.txt");
			ftp_rename($conn_id,$file_name,$new_name);

			// close the FTP stream
			ftp_close($conn_id);
			
			//return true;
			
			// check upload status
			if (!$result) {
				return false;
			} else {
				return true;
			}
			
		}
	}

	function renameFTPFile($old_file, $new_file)
	{
		$conn_id = ftp_connect("ip_address_comes_here") or die('could not connect');
		$login_result = ftp_login($conn_id, 'ftpuser', 'FtpU$er');
		
		ftp_chdir($conn_id, '/NDETestFolder/');
		//ftp_rename($conn_id,"oldname.txt","newname.txt");
		ftp_rename($conn_id,"eusa_wall.gif","rajdya.gif");
		
		ftp_close($conn_id);	
		
		return true;
	}

Revision: 43159
at March 18, 2011 02:15 by erraja_07


Initial Code
function connectToFTP($file_name,$download_to,$new_name)
	{	
		$conn_id = ftp_connect("221.134.108.196") or die('could not connect');
		$login_result = ftp_login($conn_id, 'ftpuser', 'FtpU$er');
		
		$dir_path = '/NDE Test Folder/';
		
		if ((!$conn_id) || (!$login_result)) {
			//echo "FTP connection has failed!";
			//exit;
			return false;
		} else {
			//echo 'connected'; die;
			// get the file
			$local = fopen($download_to,"w");
			$result = ftp_fget($conn_id, $local,$dir_path.$file_name."", FTP_BINARY);
			
			ftp_chdir($conn_id, $dir_path);
			
			//ftp_rename($conn_id,"oldname.txt","newname.txt");
			ftp_rename($conn_id,$file_name,$new_name);

			// close the FTP stream
			ftp_close($conn_id);
			
			//return true;
			
			// check upload status
			if (!$result) {
				return false;
			} else {
				return true;
			}
			
		}
	}

	function renameFTPFile($old_file, $new_file)
	{
		$conn_id = ftp_connect("221.134.108.196") or die('could not connect');
		$login_result = ftp_login($conn_id, 'ftpuser', 'FtpU$er');
		
		ftp_chdir($conn_id, '/NDETestFolder/');
		//ftp_rename($conn_id,"oldname.txt","newname.txt");
		ftp_rename($conn_id,"eusa_wall.gif","rajdya.gif");
		
		ftp_close($conn_id);	
		
		return true;
	}

Initial URL

 

Initial Description


Initial Title
PHP FTP read and write

Initial Tags


Initial Language
PHP