
<?php
error_reporting(E_ALL);
$myVal="";

# session_start();
# include 'myfunctions.php';
 
//$server_file = "Pel2012Setup.iss";
//$server_file = $_REQUEST["file"];
$Command = $_GET['c'];
$server_file = $_GET['file'];
$myVal=$server_file . "\n";

$ftp_server = "visualsoft.gr";
$ftp_user = "customers_user";
$ftp_pass = "P@ssw0rdFtp!";

$dirname = dirname($server_file);

#$local_file= str_replace($dirname, '', $server_file);
#$local_file= str_replace("/", '', $local_file);

$local_file = explode("/", $server_file);
/* the file name … e.g name_of_file.jpg */
$local_file = end($local_file);
 
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 
    if ( ftp_login($conn_id, $ftp_user, $ftp_pass)) 
    {
			#  echo "Connected as $ftp_user@$ftp_server\n";  
	}else{
			#  echo "Couldn't connect as $ftp_use br@$ftp_server\n";  
	}
 	

# =====================================	
ftp_set_option($conn_id, FTP_USEPASVADDRESS, false); // set ftp option
ftp_pasv($conn_id, true); //make connection to passive mode
# =====================================  

if($Command=="delete"){
	if (ftp_delete($conn_id, $server_file))
	  {
	  $myVal= "Το αρχείο $server_file διαγράφηκε από τον Server";
	  }
	else
	  {
	  $myVal= "Δεν ήταν δυνατή η διαγραφή του αρχείου $server_file";
	  }

 ftp_close($conn_id); 
echo  trim($myVal) ;
exit();
}	
 

$m_dir = 'c:\\_visualsoft\\';
$m_dir = '/_visualsoft';
if(!is_dir($m_dir)) {  mkdir($m_dir,0755,true); } 
chdir($m_dir);

#$fp = fopen($m_dir.$local_file,"w");

$fp = fopen($local_file,"w");
#$fp = fopen($local_file,"w");
$local_File1=$local_file;
 
#$fp = fopen($local_file,"w");
#$d = ftp_nb_fget($conn_id, $fp, $server_file, FTP_BINARY); 

$size = ftp_size($conn_id, $server_file);
#$ret = ftp_nb_get($conn_id, $local_File1, $server_file, FTP_BINARY);

#while ($ret == FTP_MOREDATA)
#{
#  clearstatcache(true, $local_File1);
#  echo "\r".intval(filesize($local_File1)/$size*100)."%";
#  $ret = ftp_nb_continue($conn_id);
#}

#echo "\n";
  
# =====================================   
#if (ftp_nb_fget($conn_id, $fp, $server_file, FTP_BINARY )) {  
if (ftp_fget($conn_id, $fp, $server_file, FTP_BINARY )) {  
			$myVal= "Επιτυχής μεταφορά αρχείου: $local_file, \n στον φάκελο $m_dir";  
	}else{ 	$myVal= "Πρόβλημα κατα την μεταφορά αρχείου: $local_file\n"; }  
# =====================================  

 ftp_close($conn_id); 
 
//  $myVal= "The file \"" . $fp . "\" was successfully downloaded. :)\r\nSize of \"" . $fp . "\": " . filesize($fp) / 1024 ."kb.\r\n";
    //    echo "My work is done, bye.\r\n";
		
// $myVal = $myVal .  "Πρόβλημα κατα την μεταφορά του αρχείου = $local_file\n";
 // $myVal = $myVal ."\n". sys_get_temp_dir() ."\n  get_current_user=". get_current_user() ."\n REMOTE_ADDR=" . getenv('REMOTE_ADDR'); ;
 
echo  trim($myVal) ;

?>
 
 
 
  
