<?php
	require("../../inc/lib.inc");
?>
<?php
	$dstSeverIp=$_REQUEST['dstSeverIp'];
	$ftpLoginName=$_REQUEST['ftpLoginName'];
	$localFileName=$_REQUEST['localFileName'];
	$remoteFileName=$_REQUEST['remoteFileName'];
	$ftpLoginPwd=$_REQUEST['ftpLoginPwd'];
	$logFileName=$_REQUEST['logFileName'];
	//$logFileUrl="./get_log_file.php?dstSeverIp={$dstSeverIp}&ftpLoginName={$ftpLoginName}&ftpLoginPwd={$ftpLoginPwd}&localFileName={$localFileName}&remoteFileName={$remoteFileName}&logFileName={$logFileName}";
	system("rm -rf ../../../ftpFile/*.log");
	$connection=sftp_connect($dstSeverIp);
	if($connection < 0){
		echo "<br><font color=\"#FF0000\">Connect [$dstSeverIp] Failed!</font>";
		exit();	
	}
	$key=sftp_login($connection,$ftpLoginName,$ftpLoginPwd);
	if(!$key)
	{
		echo "<br><font color=\"#FF0000\">Login Failed!</font>";
		exit();	
	}
	//echo "sftp_get($key,$localFileName,$remoteFileName)<br>";
	if(!sftp_get($key,$localFileName,$remoteFileName,SFTP_ASCII))
	{
		echo "<br><font color=\"#FF0000\">Get log file Failed</font>";
		exit();	
	}

	header("Content-type: application/txt");
	header("Content-Disposition: attachment; filename=$logFileName");
	
	//use for download csv in https
	header('Expires: 0'); 
	header('Pragma: public'); 
	header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
	header('Cache-Control: public'); 
	
	readfile("../../../ftpFile/$logFileName");
?>

