FTP Interface

Posted: August 26, 2011 in PHP
<? session_start();
    set_time_limit(0);
	require 'ftp.php';		
	error_reporting(0);	
	if($_POST['act']=='doNow' && isset($_POST['act']))
	{
		$ftpHost = trim($_POST['ftpHost']);
		$ftpUsername = trim($_POST['ftpUsername']);
		$ftpPassword = trim($_POST['ftpPassword']);
		$mode = trim($_POST['mode']);
		$localPath = rtrim(trim($_POST['localPath']),'\\');		
		$livePath = rtrim(trim($_POST['livePath']),'/'); 
		if($ftpHost=="" || $ftpUsername=="" || $ftpPassword=="" || $mode=="" || $localPath=="" || $livePath=="")
		{
			$_SESSION['msg'] = '<strong style="color:#CC0000;">Please enter all values.</strong>';
			header('Location:interface.php');
			exit;
		}		
		if(!file_exists($localPath))
		{
			$_SESSION['msg'] = '<strong style="color:#CC0000;">Local path doesn\'t exist.</strong>';
			header('Location:interface.php');
			exit;
		}
		
		$ftp = new ftp();
		$ftp->conn($ftpHost, $ftpUsername, $ftpPassword);
		if($mode == 'put')
			$ftp->put($livePath,$localPath);
		if($mode == 'get')
			$ftp->get($localPath,$livePath);
		$arr = $ftp->getLogData();		
		$str.= '<h4>Log:</h4>'.implode('<br />',$arr);		
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FTP Interface</title>
<style>
table td{ background-color:#F2F2F2;}
</style>
</head>

<body><br /><br /><br />
<? if($_POST['act']=='doNow' && isset($_POST['act'])) { ?>
<table align="center" bgcolor="#CCCCCC" width="900" border="0" cellspacing="1" cellpadding="5">
<tr>
   <td  align="center"><h3>FTP Interface</h3></td>
 </tr>
 <tr>
   <td align="left"><?=$str;?></td>
 </tr>
 </table>
<? } else { ?>
<form id="form1" name="form1" method="post" action="">
<input type="hidden" name="act" value="doNow" />
<table align="center" bgcolor="#CCCCCC" width="600" border="0" cellspacing="1" cellpadding="5">
 <tr>
   <td colspan="2" align="center"><h3>FTP Interface</h3></td>
 </tr>
 
 <tr>
    <td width="178" align="right">FTP Host :</td>
    <td width="399">
      <input type="text" style="width:300px;" name="ftpHost" />    </td>
  </tr>
  <tr>
    <td align="right">Username :</td>
    <td><input type="text" style="width:300px;" name="ftpUsername" /></td>
  </tr>
  <tr>
    <td align="right">Password :</td>
    <td><input type="password" style="width:300px;" name="ftpPassword" /></td>
  </tr>
  <tr>
    <td align="right">&nbsp;</td>
    <td>
    <label><input type="radio" name="mode" value="get" /> Download </label>
    <label><input type="radio" name="mode" value="put" /> Upload </label>    </td>
  </tr>
  <tr>
    <td align="right">Local  Path :</td>
    <td><input type="text" style="width:300px;" name="localPath" /></td>
  </tr>
  <tr>
    <td align="right">Live Path : </td>
    <td><input type="text" style="width:300px;" name="livePath" /></td>
  </tr>
  <? if(isset($_SESSION['msg'])){ ?>
  <tr>
    <td align="right"></td>
    <td><?=$_SESSION['msg'];?></td>
  </tr>  
  <? unset($_SESSION['msg']);} ?>
  <tr>
    <td>&nbsp;</td>
    <td>
      <input type="submit" name="button" id="button" value="Submit" />
      <br /> <br />    
      </td>
  </tr>
</table>
</form>
<? } ?>
</body>
</html>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s