<?php
$host=$_POST['host_server'];
$port=$_POST['port_server'];
$user=$_POST['ftp_user'];
$password=$_POST['ftp_pwd'];
?>
<html>
<head>
</head>
<body style="font-family:'Courier New', Courier, monospace">
<form name="form1" method="post" action="">
  <table width="200" >
    <tr>
      <th colspan="4" nowrap scope="col">CONEXI&Oacute;N FTP </th>
    </tr>
    <tr>
      <th nowrap scope="col">HOST:</th>
      <th nowrap scope="col"><label>
        <input name="host_server" type="text" id="host_server" value="<? echo  $_REQUEST['host_server']; ?>">
      </label></th>
      <th nowrap scope="col">PUERTO:</th>
      <th nowrap scope="col"><input name="port_server" type="text" id="port_server" value="<? echo  $_REQUEST['port_server']; ?>"></th>
    </tr>
    <tr>
      <th nowrap scope="col">USUARIO:</th>
      <th nowrap scope="col"><label>
        <input name="ftp_user" type="text" id="ftp_user" value="<? echo  $_REQUEST['ftp_user']; ?>">
      </label></th>
      <th nowrap scope="col">PASSWORD:</th>
      <th nowrap scope="col"><input name="ftp_pwd" type="text" id="ftp_pwd" value="<? echo  $_REQUEST['ftp_pwd']; ?>"></th>
    </tr>
    <tr>
      <th colspan="2" nowrap scope="col">ORIGEN</th>
      <th colspan="2" nowrap scope="col">DESTINO</th>
    </tr>
    <tr>
      <th nowrap scope="col"><label>
      Archivo:        </label></th>
      <th nowrap scope="col"><input name="nom_arc_ori" type="text" id="nom_arc_ori" value="<? echo  $_REQUEST['nom_arc_ori']; ?>"></th>
      <th nowrap scope="col">ARHIVO:</th>
      <th nowrap scope="col"><input name="nom_arc_des" type="text" id="nom_arc_des" value="<? echo  $_REQUEST['nom_arc_des']; ?>"></th>
    </tr>
    <tr>
      <td colspan="4" nowrap>
      <input name="pro_con" type="submit" id="pro_con" value="Probar Conexion">
      <label>
      <input name="ver_con" type="submit" id="ver_con" value="Ver Contenido">
      </label>
      <label>
      <input name="dow_arc" type="submit" id="dow_arc" value="Descarga Archivo">
      <input name="up_arc" type="submit" id="up_arc" value="Subir Archivo">
      </label></td>
    </tr>
  </table>
</form>


<?php


if(isset($_POST['pro_con'])){
	if(@$ftpCon=ftp_connect($host,$port,60)){
		echo "<h2>CONEXION EXITOSA!!</h2>";
		if(@$ftpLog=ftp_login($ftpCon,$user,$password)){
			echo "<h2>LOGIN CON EXITO</h2>";
		}else{
			echo "<h3>ERROR DE AUTENTIFICACION</h3>";
			exit();	
		}
	}else{
		echo "<h2>ERROR DE CONEXION</h2>";
		exit();
	}
}
if(isset($_POST['ver_con'])){
	if(@$ftpCon=ftp_connect($host,$port,60)){
		echo "<h2>CONEXION EXITOSA!!</h2>";
		if(@$ftpLog=ftp_login($ftpCon,$user,$password)){
			echo "<h2>LOGIN CON EXITO</h2>";
		}else{
			echo "<h3>ERROR DE AUTENTIFICACION</h3>";
			exit();	
		}
	}else{
		echo "<h2>ERROR DE CONEXION</h2>";
		exit();
	}
	
	$archivos=ftp_nlist($ftpCon,".");
	for($i=0;$i<count($archivos);$i++){
		echo $archivos[$i]."<br>";
	}
}


if(isset($_POST['dow_arc'])){
	if(@$ftpCon=ftp_connect($host,$port,60)){
		echo "<h2>CONEXION EXITOSA!!</h2>";
		if(@$ftpLog=ftp_login($ftpCon,$user,$password)){
			echo "<h2>LOGIN CON EXITO</h2>";
		}else{
			echo "<h3>ERROR DE AUTENTIFICACION</h3>";
			exit();	
		}
	}else{
		echo "<h2>ERROR DE CONEXION</h2>";
		exit();
	}
	$fileOri=$_POST['nom_arc_ori'];
	$fileDes=$_POST['nom_arc_des'];	
	if(ftp_get($ftpCon,"archivos/$fileDes",$fileOri,FTP_BINARY)){
		echo "<h3>TRANSFERENCIA EXITOSA --DOWNLOAD!!</h3>";
	}else{
		echo "<h3>ERROR AL TRANSFERIR ARCHIVO!!</h3>";
	}
}

if(isset($_POST['up_arc'])){
	if(@$ftpCon=ftp_connect($host,$port,60)){
		echo "<h2>CONEXION EXITOSA!!</h2>";
		if(@$ftpLog=ftp_login($ftpCon,$user,$password)){
			echo "<h2>LOGIN CON EXITO</h2>";
		}else{
			echo "<h3>ERROR DE AUTENTIFICACION</h3>";
			exit();	
		}
	}else{
		echo "<h2>ERROR DE CONEXION</h2>";
		exit();
	}
	$fileOri=$_POST['nom_arc_ori'];
	$fileDes=$_POST['nom_arc_des'];	
	if(ftp_put($ftpCon,"$fileDes","archivos/$fileOri",FTP_BINARY)){
		echo "<h3>TRANSFERENCIA EXITOSA  --UPLOAD!!</h3>";
	}else{
		echo "<h3>ERROR AL TRANSFERIR ARCHIVO!!</h3>";
	}
}
?>
</body>
</html>
