<?php
# FTPeasy class
# coded by Alessandro Rosa
# e-mail : zandor_zz@yahoo.it
# site : http://malilla.supereva.it
# LAST UPDATE : March 3th 2007
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License v2 as published by
# the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Compiled with PHP 4.4.4
function formatMEMsize( $bytes )
{
$MbONE = 1024 * 1024 ;
$KbONE = 1024 ;
if ( intval( $bytes ) < $KbONE ) return "$bytes bytes" ;
else if ( intval( $bytes / $KbONE ) < 800 )
{
$mem = intval( $bytes / $KbONE );
$remainder = substr( $bytes % $KbONE, 0, 1 ) ;
return "$mem.$remainder Kb" ;
}
else
{
$mem = intval( $bytes / $MbONE );
$remainder = substr( $bytes % $MbONE, 0, 1 ) ;
return "$mem.$remainder Mb" ;
}
}
define( BINARY, FTP_BINARY ) ;
define( ASCII, FTP_ASCII ) ;
define( STATUS_OPERATIVE, 1 ) ;
define( STATUS_BROKEN, 0 ) ;
define( STATUS_INDETERMINATE, -1 ) ;
define( DOWNLOAD_FAILED, 0 ) ;
define( DOWNLOAD_OK, 1 ) ;
define( DOWNLOAD_NO_OVERWRITE_PERMISSIONS, 2 ) ;
define( UPLOAD_FAILED, 0 ) ;
define( UPLOAD_OK, 1 ) ;
class FTPeasy
{
function FTPeasy()
{
$this->FTPcredentials = array();
$this->bHIDEpassword = false ;
$this->bAutomatic = true ;
$this->bFORCEoverwrite = false ;
}
function FTPconfigure( $referrer, $host, $uID, $pwd, $port, $tMODE, $bSAFE_SSL )
{
$countITEMs = 0 ;
// strip out useless stuff, if any ;
$host = str_replace( "ftp://", "", $host ) ;
// checks that all arrays fulfillment was OK
if ( isset( $referrer ) && strlen( $referrer ) > 0 ) $countITEMs++ ;
else $this->errors[] = "Missing REFERRER NAME" ;
if ( isset( $uID ) && strlen( $uID ) > 0 ) $countITEMs++ ;
else $this->errors[] = "Missing USERID" ;
if ( isset( $host ) && strlen( $host ) > 0 ) $countITEMs++ ;
else $this->errors[] = "Missing HOST IP" ;
if ( isset( $pwd ) && strlen( $pwd ) > 0 ) $countITEMs++ ;
else $this->errors[] = "Missing PASSWORD" ;
if ( eregi( "^[0-9]{1,}$", $port ) && isset( $port ) && strlen( $port ) > 0 ) $countITEMs++ ;
else $this->errors[] = "Missing PORT NUMBER" ;
if ( ( $tMODE == BINARY || $tMODE == ASCII ) && isset( $tMODE ) && strlen( $tMODE ) > 0 ) $countITEMs++ ;
else $this->errors[] = "Missing TRANSFER MODE" ;
if ( isset( $bSAFE_SSL ) ) $countITEMs++ ;
else $this->errors[] = "Missing SECURE MODE" ;
if ( $countITEMs == 7 )
{
$element = array( "referrer" => $referrer,
"host" => $host,
"id" => $uID,
"password" => $pwd,
"port" => $port,
"transfermode" => $tMODE,
"status" => STATUS_INDETERMINATE,
"connection" => 0,
"safe_ssl" => $bSAFE_SSL,
"os" => ""
);
if ( !( $this->FTPfindCONNECTION( $referrer, $connection ) ) )
{
$this->FTPcredentials[$referrer] = $element ;
return true ;
}
else return false ;
}
else return false ;
}
function FTPcheckCONNECTIONS()
{
foreach( $this->FTPcredentials as $credential )
{
$referrer = $credential["referrer"] ;
if ( $this->FTPconnect( $referrer ) )
{
$this->FTPcredentials[ $referrer ]["status"] = STATUS_OPERATIVE ;
$this->FTPcredentials[ $referrer ]["os"] = ftp_systype( $this->FTPcredentials[ $referrer ]["connection"] );
$this->FTPdisconnect( $referrer ) ;
}
else $this->FTPcredentials[ $referrer ]["status"] = STATUS_BROKEN ;
}
}
function FTPfindCONNECTION( $referrer, &$connection )
{
if ( is_string( $referrer ) )
return ( is_array( $this->FTPcredentials[ $referrer ] ) ) ? true : false ;
else return false ;
}
function FTPdeleteENTRY( $referrer )
{
if ( !is_string( $referrer ) ) return false ;
else
{
foreach( $this->FTPcredentials as $credential )
{
if ( strcmp( $credential[ "referrer" ], $referrer ) == 0 )
{
unset( $this->FTPcredentials[ "referrer" ] );
return true ;
}
}
}
}
function FTPlistCONNECTIONS()
{
echo "<table border=\"1\" cellpadding=\"5\" style=\"border-collapse:collapse;border:1px solid black;font-family:tahoma;font-size:10pt;\" >\r\n" ;
$i = 0 ;
echo "<tr style=\"background-color:#0000B0;color:white;font-weight:bold;\">\r\n";
echo "<td></td>\r\n";
echo "<td>REFERRER</td>\r\n";
echo "<td>HOST</td>\r\n";
echo "<td>ID</td>\r\n";
echo "<td>PSW</td>\r\n";
echo "<td>FTP PORT</td>\r\n";
echo "<td>TRANSFER MODE</td>\r\n";
echo "<td>SAFE SSL</td>\r\n";
echo "<td>OS</td>\r\n";
echo "<td>STATUS</td>\r\n";
echo "</tr>\r\n";
foreach( $this->FTPcredentials as $credential )
{
$i++ ;
echo "<tr style=\"background-color:white;border-bottom:2px solid black;\">";
echo "<td>$i</td>" ;
echo "<td><b>".$credential["referrer"]."</b></td>" ;
echo "<td>".$credential["host"]."</td>" ;
echo "<td>".$credential["id"]."</td>" ;
echo "<td>".( ( $this->bHIDEpassword ) ? "*********" : $credential['password'] )."</td>" ;
echo "<td>".$credential["port"]."</td>" ;
echo "<td>".(( $credential["transfermode"] == BINARY ) ? "BINARY" : "ASCII" )."</td>" ;
echo "<td>".(( $credential["safe_ssl"] == BINARY ) ? "YES" : "NO" )."</td>" ;
echo "<td>".$credential["os"]."</td>" ;
$status = "" ;
switch( $credential["status"] )
{
case STATUS_OPERATIVE:
$status = "Operative" ;
break;
case STATUS_BROKEN:
$status = "Broken" ;
break;
case STATUS_INDETERMINATE:
$status = "Unknown" ;
break;
}
echo "<td>$status</td>\r\n" ;
echo "</tr>\r\n";
}
echo "</table>\r\n" ;
}
function FTPconnect( $referrer )
{
if ( $this->FTPfindCONNECTION( $referrer, $connection ) )
{
$tag = $this->FTPcredentials[$referrer][ "referrer" ] ;
$host = $this->FTPcredentials[$referrer][ "host" ] ;
$port = $this->FTPcredentials[$referrer][ "port" ] ;
$bSAFE_SSL = $this->FTPcredentials[$referrer][ "safe_ssl" ] ;
$this->FTPcredentials[$tag]["connection"] = ( $bSAFE_SSL ) ? ftp_ssl_connect( $host , $port ) : ftp_connect( $host , $port );
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
$bOK = ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
( strcmp( $resourceTYPE , "ftp buffer" ) == 0 ) ) ? true : false ;
$this->status = $bOK ;
return $bOK ;
}
else
{
$this->status = false ;
return false ;
}
}
function FTPlogin( $referrer )
{
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
ftp_login( $this->FTPcredentials[$referrer]["connection"],
$this->FTPcredentials[$referrer]["id"],
$this->FTPcredentials[$referrer]["password"] );
}
else return false ;
}
function FTPgetTIMEOUT( $referrer )
{
if ( $this->bAutomatic ) $this->FTPconnect( $referrer ) ;
if ( !$this->status ) return ;
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
if ( $this->bAutomatic ) $this->FTPlogin( $referrer );
$timeout = ftp_get_option( $this->FTPcredentials[$referrer]["connection"],
FTP_TIMEOUT_SEC );
if ( $this->bAutomatic ) $this->FTPdisconnect( $referrer ) ;
return $timeout ;
}
else return false ;
}
function FTPfilePERMISSIONS( $referrer, $filePATHandNAME, $octalVALUE )
{
// FILE PERMISSIONS MANAGEMENT is not supported by lower versions
if ( strpos( phpversion(), 5 ) !== 0) return false ;
if ( $this->bAutomatic ) $this->FTPconnect( $referrer ) ;
if ( !$this->status ) return ;
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
if ( $this->bAutomatic ) $this->FTPlogin( $referrer );
$dirname = dirname( $filePATHandNAME ) ;
if ( $dirname != "." && $dirname != ".." )
{
// goes into the specified input folder specified
if ( strlen( $dirname ) > 0 )
@ftp_chdir( $this->FTPcredentials[$referrer]["connection"], $dirname );
// assumes the file name only
$filePATHandNAME = str_replace( $dirname."/", "", $filePATHandNAME ) ;
}
$timeout = ftp_chmod( $this->FTPcredentials[$referrer]["connection"],
$octalVALUE,
$filePATHandNAME );
echo $filePATHandNAME ;
if ( $this->bAutomatic ) $this->FTPdisconnect( $referrer ) ;
return $timeout ;
}
else return false ;
}
function FTPsetTIMEOUT( $referrer, $timeOUTsecs )
{
// no timeout shorter than 90 seconds is allowed
if ( $timeOUTsecs < 90 ) $timeOUTsecs = 90 ;
if ( $this->bAutomatic ) $this->FTPconnect( $referrer ) ;
if ( !$this->status ) return ;
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
if ( $this->bAutomatic ) $this->FTPlogin( $referrer );
$timeout = ftp_set_option( $this->FTPcredentials[$referrer]["connection"],
FTP_TIMEOUT_SEC,
$timeOUTsecs );
if ( $this->bAutomatic ) $this->FTPdisconnect( $referrer ) ;
return $timeout ;
}
else return false ;
}
function FTPexecute( $referrer, $programPATHandNAMEandCOMMANDS )
{
if ( $this->bAutomatic ) $this->FTPconnect( $referrer ) ;
if ( !$this->status ) return ;
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
if ( $this->bAutomatic ) $this->FTPlogin( $referrer );
$dirname = dirname( $programPATHandNAMEandCOMMANDS ) ;
if ( $dirname != "." && $dirname != ".." )
{
// goes into the specified input folder specified
if ( strlen( $dirname ) > 0 )
@ftp_chdir( $this->FTPcredentials[$referrer]["connection"], $dirname );
// assumes the file name only
$programPATHandNAMEandCOMMANDS = str_replace( $dirname."/", "", $programPATHandNAMEandCOMMANDS ) ;
}
$ret = ftp_exec( $this->FTPcredentials[$referrer]["connection"],
$programPATHandNAMEandCOMMANDS );
if ( $this->bAutomatic ) $this->FTPdisconnect( $referrer ) ;
return $ret ;
}
else return false ;
}
function FTPtimeMODIFY( $referrer, $programPATHandNAME )
{
if ( $this->bAutomatic ) $this->FTPconnect( $referrer ) ;
if ( !$this->status ) return ;
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
if ( $this->bAutomatic ) $this->FTPlogin( $referrer );
$dirname = dirname( $programPATHandNAME ) ;
if ( $dirname != "." && $dirname != ".." )
{
// goes into the specified input folder specified
if ( strlen( $dirname ) > 0 )
@ftp_chdir( $this->FTPcredentials[$referrer]["connection"], $dirname );
// assumes the file name only
$programPATHandNAME = str_replace( $dirname."/", "", $programPATHandNAME ) ;
}
$ret = ftp_mdtm( $this->FTPcredentials[$referrer]["connection"],
$programPATHandNAME );
if ( $this->bAutomatic ) $this->FTPdisconnect( $referrer ) ;
if ( $ret != -1 ) return date("F d Y H:i:s.", $ret );
else return false ;
}
else return false ;
}
function FTPcreateFOLDER( $referrer, $folderNAME )
{
if ( $this->bAutomatic ) $this->FTPconnect( $referrer ) ;
if ( !$this->status ) return ;
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
if ( $this->bAutomatic ) $this->FTPlogin( $referrer );
// erases ending slash '/' if any
$lastCHAR = $folderNAME{ strlen( $folderNAME ) - 1 } ;
if ( strcmp( $lastCHAR, "/" ) == 0 )
$folderNAME = substr( $folderNAME, 0, strlen( $folderNAME ) - 1 );
$dirNAME = dirname( $folderNAME ) ;
if ( $dirname != "." && $dirname != ".." )
{
if ( strlen( $dirname ) > 0 )
@ftp_chdir( $this->FTPcredentials[$referrer]["connection"], $dirname ) ;
// assumes the name only
$deepestFOLDER = str_replace( $dirname, "", $folderNAME ) ;
// create the folder
$ret = @ftp_mkdir( $this->FTPcredentials[$referrer]["connection"], $deepestFOLDER );
}
if ( $this->bAutomatic ) $this->FTPdisconnect( $referrer ) ;
return ( $ret === false ) ? false : true ;
}
else return false ;
}
function FTPremoveFOLDER( $referrer, $folderNAME )
{
if ( $this->bAutomatic ) $this->FTPconnect( $referrer ) ;
if ( !$this->status ) return ;
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
if ( $this->bAutomatic ) $this->FTPlogin( $referrer );
// erases ending slash '/' if any
$lastCHAR = $folderNAME{ strlen( $folderNAME ) - 1 } ;
if ( strcmp( $lastCHAR, "/" ) == 0 )
$folderNAME = substr( $folderNAME, 0, strlen( $folderNAME ) - 1 );
$dirNAME = dirname( $folderNAME ) ;
if ( $dirname != "." && $dirname != ".." )
{
if ( strlen( $dirname ) > 0 )
@ftp_chdir( $this->FTPcredentials[$referrer]["connection"], $dirname ) ;
// assumes the name only
$deepestFOLDER = str_replace( $dirname, "", $folderNAME ) ;
// create the folder
$ret = @ftp_rmdir( $this->FTPcredentials[$referrer]["connection"], $deepestFOLDER );
}
if ( $this->bAutomatic ) $this->FTPdisconnect( $referrer ) ;
return ( $ret === false ) ? false : true ;
}
else return false ;
}
function FTPdelete( $referrer, $filePATHandNAME )
{
if ( $this->bAutomatic ) $this->FTPconnect( $referrer ) ;
if ( !$this->status ) return ;
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
if ( $this->bAutomatic ) $this->FTPlogin( $referrer );
$dirname = dirname( $filePATHandNAME ) ;
if ( $dirname != "." && $dirname != ".." )
{
// goes into the specified input folder specified
if ( strlen( $dirname ) > 0 )
@ftp_chdir( $this->FTPcredentials[$referrer]["connection"], $dirname );
// assumes the file name only
$filePATHandNAME = str_replace( $dirname."/", "", $filePATHandNAME ) ;
}
$ret = ftp_delete( $this->FTPcredentials[$referrer]["connection"],
$filePATHandNAME );
if ( $this->bAutomatic ) $this->FTPdisconnect( $referrer ) ;
return $ret ;
}
else return false ;
}
function FTPrenameFILE( $referrer, $path, $oldNAME, $newNAME )
{
if ( $this->bAutomatic ) $this->FTPconnect( $referrer ) ;
if ( !$this->status ) return ;
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
if ( $this->bAutomatic ) $this->FTPlogin( $referrer );
if ( $path != "." && $path != ".." )
{
// goes into the specified input folder specified
if ( strlen( $path ) > 0 )
@ftp_chdir( $this->FTPcredentials[$referrer]["connection"], $path );
}
$ret = ftp_rename( $this->FTPcredentials[$referrer]["connection"],
$oldNAME, $newNAME );
if ( $this->bAutomatic ) $this->FTPdisconnect( $referrer ) ;
return $ret ;
}
else return false ;
}
function FTPsetPASSIVEmode( $referrer, $bPASSIVE )
{
if ( $this->bAutomatic ) $this->FTPconnect( $referrer ) ;
if ( !$this->status ) return ;
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
if ( $this->bAutomatic ) $this->FTPlogin( $referrer );
$ret = ftp_pasv( $this->FTPcredentials[$referrer]["connection"],
$bPASSIVE );
if ( $this->bAutomatic ) $this->FTPdisconnect( $referrer ) ;
return $ret ;
}
else return false ;
}
function FTPsize( $referrer, $filePATHandNAME, $bFormat )
{
if ( $this->bAutomatic ) $this->FTPconnect( $referrer ) ;
if ( !$this->status ) return ;
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
if ( $this->bAutomatic ) $this->FTPlogin( $referrer );
$dirname = dirname( $filePATHandNAME ) ;
if ( $dirname != "." && $dirname != ".." )
{
// goes into the specified input folder specified
if ( strlen( $dirname ) > 0 )
@ftp_chdir( $this->FTPcredentials[$referrer]["connection"], $dirname );
// assumes the file name only
$filePATHandNAME = str_replace( $dirname."/", "", $filePATHandNAME ) ;
}
$ret = ftp_size( $this->FTPcredentials[$referrer]["connection"],
$filePATHandNAME );
$ret = ( $bFormat ) ? formatMEMsize( $ret ) : $ret ;
if ( $this->bAutomatic ) $this->FTPdisconnect( $referrer ) ;
return $ret ;
}
else return false ;
}
function FTPdir( $referrer, $filePATH, $bDetailedMODE )
{
if ( $this->bAutomatic ) $this->FTPconnect( $referrer ) ;
if ( !$this->status ) return ;
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
if ( $this->bAutomatic ) $this->FTPlogin( $referrer );
// erases ending slash '/' if any
$lastCHAR = $filePATH{ strlen( $filePATH ) - 1 } ;
if ( strcmp( $lastCHAR, "/" ) == 0 )
$filePATH = substr( $filePATH, 0, strlen( $filePATH ) - 1 );
$dirname = dirname( $filePATH ) ;
if ( $dirname != "." && $dirname != ".." )
{
// goes into the specified input folder specified
if ( strlen( $dirname ) > 0 )
@ftp_chdir( $this->FTPcredentials[$referrer]["connection"], $dirname );
// assumes the file name only
$filePATH = str_replace( $dirname."/", "", $filePATH ) ;
}
if ( $bDetailedMODE )
$ret = ftp_rawlist( $this->FTPcredentials[$referrer]["connection"],
$filePATH );
else
$ret = ftp_nlist( $this->FTPcredentials[$referrer]["connection"],
$filePATH );
if ( $this->bAutomatic ) $this->FTPdisconnect( $referrer ) ;
return "<pre>".print_r( $ret, true )."</pre>" ;
}
else return false ;
}
function FTPupload( $referrer, $remoteFILENAME, $localFILENAME )
{
if ( $this->bAutomatic ) $this->FTPconnect( $referrer ) ;
if ( !$this->status ) return ;
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
if ( !isset( $this->FTPcredentials[$referrer]["transfermode"] ) &&
( $this->FTPcredentials[$referrer]["transfermode"] == ASCII || $this->FTPcredentials[$referrer]["transfermode"] == BINARY ) )
$ftpTrMODE = $this->FTPcredentials[$referrer]["transfermode"] ;
else $ftpTrMODE = $this->FTPcredentials[$referrer]["transfermode"] = BINARY ; // default mode
if ( $this->bAutomatic ) $this->FTPlogin( $referrer );
$dirname = dirname( $remoteFILENAME ) ;
if ( $dirname != "." && $dirname != ".." )
{
// goes into the specified input folder specified
if ( strlen( $dirname ) > 0 )
@ftp_chdir( $this->FTPcredentials[$referrer]["connection"], $dirname );
// assumes the file name only
$remoteFILENAME = str_replace( $dirname."/", "", $remoteFILENAME ) ;
}
$hFILElocal = fopen( $localFILENAME, "r" );
$ret = ftp_nb_fput( $this->FTPcredentials[$referrer]["connection"],
$remoteFILENAME, $hFILElocal,
$ftpTrMODE );
while ( $ret == FTP_MOREDATA ) {
// Do whatcha want ... for example
// echo ".";
// ob_flush(); flush();
// Continue uploading...
$ret = ftp_nb_continue( $this->FTPcredentials[$referrer]["connection"] );
}
fclose( $hFILElocal );
if ( $ret != FTP_FINISHED ) return UPLOAD_FAILED ;
else return UPLOAD_OK ;
if ( $this->bAutomatic ) $this->FTPdisconnect( $referrer ) ;
}
else return false ;
}
function FTPdownload( $referrer, $localFILENAME, $remoteFILENAME )
{
if ( $this->bAutomatic ) $this->FTPconnect( $referrer ) ;
if ( !$this->status ) return ;
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
{
if ( !isset( $this->FTPcredentials[$referrer]["transfermode"] ) &&
( $this->FTPcredentials[$referrer]["transfermode"] == ASCII || $this->FTPcredentials[$referrer]["transfermode"] == BINARY ) )
$ftpTrMODE = $this->FTPcredentials[$referrer]["transfermode"] ;
else $ftpTrMODE = $this->FTPcredentials[$referrer]["transfermode"] = BINARY ; // default mode
if ( $this->bAutomatic ) $this->FTPlogin( $referrer );
$dirname = dirname( $remoteFILENAME ) ;
if ( $dirname != "." && $dirname != ".." )
{
// goes into the specified input folder specified
if ( strlen( $dirname ) > 0 )
@ftp_chdir( $this->FTPcredentials[$referrer]["connection"], $dirname );
// assumes the file name only
$remoteFILENAME = str_replace( $dirname."/", "", $remoteFILENAME ) ;
}
if ( file_exists( $localFILENAME ) && !$this->bFORCEoverwrite )
return DOWNLOAD_NO_OVERWRITE_PERMISSIONS ;
$hFILElocal = fopen( $localFILENAME, "w+" );
$ret = ftp_nb_fget( $this->FTPcredentials[$referrer]["connection"],
$hFILElocal, $remoteFILENAME,
$ftpTrMODE );
while ( $ret == FTP_MOREDATA ) {
// Do whatcha want ... for example
// echo ".";
// ob_flush(); flush();
// Continue uploading...
$ret = ftp_nb_continue( $this->FTPcredentials[$referrer]["connection"] );
}
fclose( $hFILElocal );
if ( $ret != FTP_FINISHED ) return DOWNLOAD_FAILED ;
else return DOWNLOAD_OK ;
if ( $this->bAutomatic ) $this->FTPdisconnect( $referrer ) ;
}
else return false ;
}
function FTPdisconnect( $referrer )
{
$resourceTYPE = strtolower( get_resource_type( $this->FTPcredentials[$referrer]["connection"] ) );
if ( is_resource( $this->FTPcredentials[$referrer]["connection"] ) &&
strcmp( $resourceTYPE, "ftp buffer" ) == 0 &&
$this->FTPcredentials[$referrer]["status"] == STATUS_OPERATIVE )
ftp_close( $this->FTPcredentials[$referrer]["connection"] ) ;
}
////////////// MANAGEMENT MEMBER FUNCTIONS ////////////////////////////////////////////////
function setUSERid( $referrer, $uID ) { $this->FTPcredentials[ $referrer ][ "id" ] = $uID ; }
function getUSERid( $referrer ) { return $this->FTPcredentials[ $referrer ][ "id" ] ; }
function setFTPhost( $referrer, $ftpS ) { $this->FTPcredentials[ $referrer ][ "host" ] = $ftpS ; }
function getFTPhost( $referrer ) { return $this->FTPcredentials[ $referrer ][ "host" ] ; }
function setPWD( $referrer, $p ) { $this->FTPcredentials[ $referrer ][ "password" ] = $p ; }
function getPWD( $referrer ) { return $this->FTPcredentials[ $referrer ][ "password" ] ; }
function setPORT( $referrer, $p ) { $this->FTPcredentials[ $referrer ][ "port" ] = $p ; }
function getPORT( $referrer ) { return $this->FTPcredentials[ $referrer ][ "port" ] ; }
function setSAFEconnection( $referrer, $bSAFE ) { $this->FTPcredentials[ $referrer ][ "safe_ssl" ] = $bSAFE ; }
function getSAFEconnection( $referrer ) { return $this->FTPcredentials[ $referrer ][ "safe_ssl" ] ; }
function setFTPtransferMODE( $ftpTm )
{
if ( $ftpTm == ASCII || $ftpTm == BINARY ) $this->FTPcredentials[ $referrer ][ "transfermode" ] = $ftpTm ;
else $this->FTPcredentials[ $referrer ][ "transfermode" ] = BINARY ; // default mode
}
function getFTPtransferMODE( $referrer ) { return $this->FTPcredentials[ $referrer ][ "transfermode" ] ; }
function HIDEpassword( $bHide ) { $this->bHIDEpassword = $bHide ; }
// call login and disconnect automatically before and after performing the given operation
// NOTE: it may be good for beginners, but it could be odd for experts, hence
// one can disable this option via code, so to login and disconnect when desired
function setAutomaticMODE( $bAuto ) { $this->bAutomatic = $bAuto ; }
function getAutomaticMODE() { return $this->bAutomatic ; }
function setFORCEoverwrite( $bFo ) { $this->bFORCEoverwrite = $bFO ; }
function getFORCEoverwrite() { return $this->bFORCEoverwrite ; }
function display_errors() { foreach( $err as $this->errors ) echo "$err<br>" ; }
var $FTPcredentials ;
var $FTPconnection ;
var $bHIDEpassword ;
var $bAutomatic ;
var $bFORCEoverwrite ;
var $errors = array();
var $status = true ;
}
?>
|