FTP System with Auto Mail

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hai all
 i have now done a ftp script with auto mail functionality. This program
checks for the folder with todays date and if not exists create it or else
if exists then upload the files.
Please check this code and send me the comments.

*<html>
  <head><title>FTP System with Auto Mail </title>

  <body >

      <form enctype="multipart/form-data" action="/chaitu/dircheck.php"
method="POST">
<table width="500" border="0" cellspacing="4" cellpadding="4"
align="center">
  <tr>
    <td width="128">Server IP Address:</td>
    <td width="344"><input name="serverip" type="text" id="serverip"
size="50" value="192.168.0.35"/></td>
  </tr>
  <tr>
    <td>Server Username:</td>
    <td><input name="username" type="text" id="username" size="50"
value="ftp"/></td>
  </tr>
  <tr>
    <td>Server Password:</td>
    <td><input name="password" type="password" id="password" size="50"
value="ftp"/></td>
  </tr>
  <tr>
    <td>Handover file to Mr.:</td>
    <td><input name="filehandle" type="text" id="filehandle" size="50"
value=""/></td>
  </tr>
  <tr>
    <td>Please choose a file:</td>
    <td><input name="txt_file" type="file" id="txt_file" tabindex="1"
size="35" onchange="txt_fileName.value=txt_file.value" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input name="txt_fileName" type="hidden" id="txt_fileName"
tabindex="99" size="1" />

  <input type="submit" name="SubmitFile" value="Upload File"
accesskey="ENTER" tabindex="2" /></td>
  </tr>
</table>
</form>
  </body>
  <div align="center">Copyright © 2010,<a href="http://drvirusindia.co.cc";
target="_blank">DrVirus</a> </div>
</html>
<?php
if(isset($_POST['SubmitFile'])){
error_reporting(off);
$date_today=date("d-m-Y");
$ftp_server = trim($_REQUEST['serverip']);  //address of ftp server.
$ftp_user_name = trim($_REQUEST['username']); // Username
$ftp_user_pass = trim($_REQUEST['password']);   // Password
$ftp_handle = trim($_REQUEST['filehandle']); // file handle to

$myFile = $_FILES['txt_file']; // This will make an array out of the file
information that was stored.
$file = $myFile['tmp_name'];  //Converts the array into a new string
containing the path name on the server where your file is.
$myFileName = basename($_FILES['txt_file']['name']); //Retrieve filename out
of file path

$conn_id = ftp_connect($ftp_server);
$ftp_1=ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("cannot
conect");
$folder="To_Chennai";
function mail_p($body)
{
require_once "Mail.php";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: xxxxxxxx@xxxxxxxxxxxx' . "\r\n";
$headers .= 'From: xxxxxxxxxxxxxx' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$from = "name<mail@xxxxxxxx>";
$to = "Chaitu Mail Test<mail@xxxxxxxx>"; //example :$to = "Chaitu Mail Test<
dr.virus.india@xxxxxxxxx>";
$subject = "Hi!";

$host = ""; //mail server host name
$username = ""; //mail server autentication user id
$password = ""; //mail server autentication user password

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<span style='color:#339900'><h2>Mail successfully
sent!!</h2></span><br /><br />");
 }
}
function ftp_directory_exists($ftp, $dir)
{
   if (ftp_chdir($ftp, $dir))
    {
        //echo "Directory exists<br>";
    }
    else
    {
        echo "Directory Not exists. So trying to create one<br>";
        if(ftp_mkdir($ftp,$dir))
        {
            echo "Created Directory succesfully<br>";
            ftp_chdir($ftp, $dir);
        }
        else
        {
            echo "Cannot create new directory<br>";
        }
    }
}
function ftp_is_dir($folder) {
   global $conn_id;
   if (ftp_chdir($conn_id, $folder)) {
      ftp_chdir($conn_id, '..');
      return true;
   } else {
      return false;
   }
}
function ftp_list_diretory($ftp, $dir)
{
global $conn_id;
    if(ftp_chdir($ftp, $dir))
        {
         echo "Directory changed to $dir<br>";
        //$ftp_1=ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or
die("cannot conect");

         $contents = ftp_nlist($conn_id, "");
         //var_dump($contents);
         foreach($contents as $file) {
      if ($file!='.'&&$file!='..') {
         if (ftp_is_dir($file)) {
            echo $file . ' is a folder<br>';
         } else {
            echo $file . ' is a file<br>';
         }
      }
   }
        }
    else
        {
         echo "There was a problem while changing directory\n";
        }
}
ftp_directory_exists($conn_id, $folder);
ftp_directory_exists($conn_id, $date_today);
$destination_file = $myFileName;
$upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY);  //
upload the file
      if (!$upload)
          {  // check upload status
             echo "<span style='color:#FF0000'><h2>FTP upload of $myFileName
has failed!</h2></span> <br />";
          }
      else
          {

             $body=<<<EOF
Dear  Team,



    We have uploaded the zip file called $myFileName at  FTP site, path
mentioned below.



    Path: /$folder/$date_today/$myFileName



    Kindly hand over this to Mr. $ftp_handle.

Regards
Chaitu.

EOF;

mail_p($body); //call of function for sending mail.
}

ftp_close($conn_id);
}
?>*


Chaitanya

"A man can get discouraged many times but he is not a failure until he stops
trying..."


[Non-text portions of this message have been removed]


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux