<?php
class ftp
{
var $conn_id;
var $host;
var $user;
var $password;
var $root;
var $path;
var $u_path;
var $directory;
var $source;
var $destination;
var $handle;
var $mode;
var $file;
var $command;
var $int_mode;
//Begin connect to FTP ------------------------
function ftp($host, $user, $pass, $root, $path)
{
$this->host = $host;
$this->user = $user;
$this->password = $pass;
$this->root = $root;
$this->path = $path;
// specify ftp upload path
if ($this->path == null or substr($this->path, 0, 1) == ' ')
{
$this->u_path = $this->root;
}
else
{
$this->u_path = $this->root . $this->path . '/';
}
$this->conn_id = @ftp_connect($this->host);
@ftp_login($this->conn_id, $this->user, $this->password);
}
//End connect to FTP ------------------------
//Begin close the FTP ------------------------
function close_ftp()
{
if ($ftp_res = @ftp_close($this->conn_id)){
return $ftp_res;
}
else
{
return false;
}
}
//End close the FTP ------------------------
//Begin make dir ------------------------
function ftp_makedir($directory)
{
$this->directory = $directory;
if ($ftp_res = @ftp_mkdir($this->conn_id, $this->u_path . $this->directory))
{
return $ftp_res;
}
else
{
return false;
}
}
//End make dir ------------------------
//Begin remove dir ------------------------
function ftp_removedir($directory)
{
$this->directory = $directory;
if ($ftp_res = @ftp_rmdir($this->conn_id, $this->directory))
{
return $ftp_res;
}
else
{
return false;
}
}
//End remove dir ------------------------
//Begin file copy ------------------------
function ftp_copy($source, $destination, $mode = FTP_BINARY)
{
$this->source = $source;
$this->destination = $destination;
$f_ext = strtolower(substr(strrchr( $this->destination, '.'), 1));
if ($f_ext){
$this->handle = @fopen($this->source, 'r');
$this->mode = $mode;
if ($ftp_res = @ftp_fput($this->conn_id, $this->u_path . $this->destination, $this->handle, $this->mode))
{
return $ftp_res;
}
else
{
return false;
}
@fclose($this->handle);
}
else
{
return false;
}
}
//End file copy ------------------------
//Begin rename ------------------------
function ftp_ren($source, $destination)
{
$this->source = $source;
$this->destination = $destination;
if ($ftp_res = @ftp_rename($this->conn_id, $this->source, $this->destination))
{
return $ftp_res;
}
else
{
return false;
}
}
//End rename ------------------------
//Begin delete ------------------------
function ftp_del($source)
{
$this->source = $source;
if ($ftp_res = @ftp_delete($this->conn_id, $this->source))
{
return $ftp_res;
}
else
{
return false;
}
}
//End delete ------------------------
//Begin change directory ------------------------
function ftp_changedir($directory)
{
$this->directory = $directory;
if ($ftp_res = @ftp_chdir($this->conn_id, $this->directory))
{
return $ftp_res;
}
else
{
return false;
}
}
//End change directory ------------------------
//Begin set chmod ------------------------
function ftp_setchmod($source, $int_mode=0644)
{
$this->source = $source;
$this->int_mode = $int_mode;
if ($ftp_res = @ftp_chmod($this->conn_id, $this->int_mod, $this->$source))
{
return $ftp_res;
}
else
{
return false;
}
}
//End set chmod ------------------------
//Begin change parent directory ------------------------
function ftp_chpdir()
{
if ($ftp_res = @ftp_cdup($this->conn_id))
{
return $ftp_res;
}
else
{
return false;
}
}
//End change parent directory ------------------------
//Begin last modified date ------------------------
function ftp_lastmodified($source)
{
$this->source = $source;
if ($ftp_res = @ftp_mdtm($this->conn_id, $this->source))
{
return $ftp_res;
}
else
{
return false;
}
}
//End last modified date ------------------------
//Begin continue ------------------------
function ftp_continue()
{
if ($ftp_res = @ftp_nb_continue($this->conn_id))
{
return $ftp_res;
}
else
{
return false;
}
}
//End continue ------------------------
//Begin listing ------------------------
function ftp_listing($directory)
{
$this->directory = $directory;
if ($ftp_res = @ftp_rawlist($this->conn_id, $this->directory))
{
return $ftp_res;
}
else
{
return false;
}
}
//End listing ------------------------
//Begin current directory name ------------------------
function ftp_currentdir()
{
if ($ftp_res = @ftp_pwd($this->conn_id))
{
return $ftp_res;
}
else
{
return false;
}
}
//End current directory name ------------------------
//Begin send command ------------------------
function ftp_command($command)
{
$this->command = $command;
if ($ftp_res = @ftp_site($this->conn_id, $this->command))
{
return $ftp_res;
}
else
{
return false;
}
}
//End send command ------------------------
//Begin get size ------------------------
function ftp_getsize($source)
{
$this->source = $source;
echo $this_conn_id;
if ($ftp_res = @ftp_size($this->conn_id, $this->source))
{
return $ftp_res;
}
else
{
return false;
}
}
//End get size ------------------------
//Begin system type ------------------------
function ftp_getsystype()
{
if ($ftp_res = @ftp_systype($this->conn_id))
{
return $ftp_res;
}
else
{
return false;
}
}
//End system type ------------------------
//Begin get size ------------------------
function extention($file)
{
$this->file = $file;
$f_ext = strtolower(substr(strrchr($this->file, '.'), 1));
return($f_ext);
}
//End get size ------------------------
//Begin file exists ------------------------
function ftp_fileexists($source)
{
$this->source = $source;
$ftp_res = @ftp_size($this->conn_id, $this->source);
if ($ftp_res < 0) return false; else return true;
}
//End file exists ------------------------
}
?>