BlueShoes Application Framework made with PHP http://www.blueshoes.org/


Packageindex Classtrees Modulegroups Elementlist Report XML Files

File: C:/usr/local/lib/php/blueshoes-4.2/core/net/ftp/Bs_FtpClient.class.php
BlueShoes Application Framework - net/ftp

Bs_FtpClient

Bs_Object
   |
  +-- Bs_FtpClient

Abstract Ftp client class. needs to be subclassed.

 

public class Bs_FtpClient extends Bs_Object

Abstract Ftp client class. needs to be subclassed.
this is the minimal implementation for all ftp clients in blueshoes. this wayone can rely on the methods.you don't need to document again what's documented here. better refer to thisfile.i think that ftp transactions are only used in an admin environment and notfor spitting out live pages. so speed doesn't matter that much.requested reading:rfc 959: the official, current ftp rfc.http://www.faqs.org/rfcs/rfc959.html from 1985. i don't think thatolder rfc's should be supported or even looked at.rfc 1123: Requirements for Internet Hosts -- Application and Support(Contains important clarifications for RFC-959)rfc 2228: FTP Security Extensionsrfc 2389: Feature negotiation mechanism for the File Transfer Protocolrfc 2428: FTP Extensions for IPv6 and NATsrfc 2577: FTP Security Considerationsrfc 2640: Internationalization of the File Transfer Protocollinks: - The FTP Protocol Resource Center http://war.jgaa.com/ftp/- php manual. i think it's bad and incomplete.http://www.php.net/manual/en/ref.ftp.php//some method names come from the ftp command. example: mdtm() (returns lastmod).caution: when working with the filesystem there's always the risk of loosing data.be aware of that. take special care of these situations:- synchronization (overwritten by mistake, wrong timestamps)- broken transactions in the middle (old file killed, new incomplete)- file links and dir links (for example a recursive rmDir())knowledge base:- the ftp protocol differs to others like http and email in that 2 connectionsare used. one for the control flow, one for the data transfer.- the protocol has not been changed since 1985. (there have been extenstions.)so there are commands that are like-standard, but undocumented. they includeSIZE and MDTM and a different use of REST. also there's a problem with thereturn value of the LIST command, which has never been standardized (sucksalot).now there's a draft document for these new commands/changes and new commandsto work around the LIST problem. i really hope this makes it into a new rfc soon.see http://war.jgaa.com/ftp/draft/draft-ietf-ftpext-mlst-11.txt

Authors
Version4.0.$id$
Copyrightblueshoes.org

 
Direct known subclasses: Bs_FtpClientPhp

Methods inherited from Bs_Object

isex, isexception, tostring, tohtml, persist, unpersist, bs_object, bbsetoutput, bbawake, bbisawake, bbxmsg, bbxfunctionstart, bbxfunctionend, bbxecho, bbxvar, bbxvardump, bbforcetrace, bbbufferstart, bbbufferget, bbbufferendflush, bbbufferendclean

Public Method Summary

void

Bs_FtpClient()

constructor
void

reset()

clears up the object by resetting all class vars to its original state,
bool

connect()

Opens up an FTP connection (to the current host/port).
bool

login()

Logs in an FTP connection.
string

pwd([ string $useCache ])

Returns the current remote directory name.
string

localPwd()

Returns the current local directory name.
bool

cdUp()

Changes to the remote parent directory.
bool

localCdUp()

Changes to the local parent directory.
bool

chDir(string $directory)

Changes remote directory.
bool

localChDir()

Changes local directory.
bool

mkDir(string $directory)

Creates a remote directory.
mixed

localMkDir(string $directory)

Creates a local directory.
bool

rmDir(string $directory)

Removes a remote directory.
int

rmDirRec(string $directory)

Removes a remote directory recursively; with all content in it.
bool

localRmDir(string $directory)

Removes a local directory.
array

&nList(string $directory)

Returns a list of files in the given remote directory.
mixed

localNlist(string $directory)

Returns a list of files in the given local directory.
mixed

&rawList(string $directory, [ string $parse ])

Returns a detailed list of files in the given remote directory.
array

&parseRawList(array &$rawList)

parses the given $rawList.
array

&localRawList(string $localDir)

Returns a detailed list of files in the given local directory.
string

sysType([ string $useCache ])

Returns the system type identifier of the remote FTP server.
bool

pasv(bool $param)

Turns passive mode on or off.
bool

get(string $localFile, string $remoteFile, [ string $mode ])

Downloads a file from the FTP server.
bool

fGet(int $fp, string $remoteFile, [ string $mode ])

Downloads a file from the FTP server and saves to an open file.
bool

put(string $localFile, string $remoteFile, [ string $mode ])

Uploads a file to the FTP server.
bool

fPut(int $fp, string $remoteFile, [ string $mode ])

Uploads from an open file to the FTP server.
bool

fileExists(string $remoteFile)

tells if the given file exists on the server.
int

size(string $remoteFile)

Returns the size of the given remote file.
int

localSize(string $localFile)

Returns the size of the given local file.
int

lastMod(string $remoteFile)

Returns the last modified time of the given remote file.
int

localLastMod(string $localFile)

Returns the last modified time of the given local file.
bool

rename(string $remoteFile, string $newRemoteFile)

Renames a file on the ftp server.
bool

localRename(string $localFile, string $newLocalFile)

Renames a local file.
bool

delete(string $remoteFile)

Deletes a file on the ftp server.
bool

localDelete(string $localFile)

Deletes a local file.
void

site(string $command)

Sends a SITE command to the server.
void

quit()

Closes the FTP connection.

Private Method Summary

void

synchronizeFile(string $localFile, $remoteFile, string $direction)

void

synchronizeDir(int $localDir, $remoteDir, integer $depth, string $direction)

void

isConnected()

Warning: documentation is missing.
void

localRmDirRec()

Warning: documentation is missing.
void

localExists()

Warning: documentation is missing.
void

dirExists()

Warning: documentation is missing.
void

localDirExists()

Warning: documentation is missing.
void

set_perm( $obj, $num)

Warning: documentation is missing.
void

get_perm( $obj, string $type)

Warning: documentation is missing.
void

ftp_file_exists( $pathname)

Warning: documentation is missing.

Public Field Summary

string

$_isConnected

tells if we're connected to a server or not.
string

$host

the host to connect to.
integer

$port

the port to connect to. default is 21.
string

$anonymous

if connection should be made anonymous or not.
string

$username

if not connecting anonymous this username will be sent.
string

$password

if not connecting anonymous this password will be sent.
string

$transferMode

the transfer mode. one of [FTP_ASCII|FTP_BINARY]. default is binary.

Private Field Summary

object [unknown]

$_Bs_Date

reference to the globally used bs_date class. pseudostatic.
string

$_remotePath

also known as cwd (current working dir).
string

$_localPath

current local path
string

$_sysType

cached output of sysType()
unknown

$_remoteRootPath

Private Constant Summary

BS_FTPCLIENT_VERSION >>4.0.$x$<< Warning: documentation is missing.

Public Method Details

Bs_FtpClient

public void Bs_FtpClient( )

  constructor

Returns void


reset

public void reset( )

  clears up the object by resetting all class vars to its original state,
as if the object was newly created. reusing an object this way savesresources and time in php (instead of creating a new object).the subclassing class should implement a reset() method also, call thisone to clean up the vars of this class, and clean up it's own vars itself.and of course disconnect the connection first.

Returns void


connect

public bool connect( )

  Opens up an FTP connection (to the current host/port).

Returns bool

TRUE on success, FALSE on failure.


login

public bool login( )

  Logs in an FTP connection.
uses the current username/password.

Returns bool

TRUE on success, FALSE on failure.


pwd

public string pwd( [ string $useCache ] )

  Returns the current remote directory name.

Parameter
string $useCache = >>TRUE<<
default is TRUE. if we should use the cached information if available.
Returns string

Throws bool FALSE

localPwd

public string localPwd( )

  Returns the current local directory name.

Returns string


cdUp

public bool cdUp( )

  Changes to the remote parent directory.
it's like doing 'cd ..'.

Returns bool

TRUE on success, FALSE on failure.


localCdUp

public bool localCdUp( )

  Changes to the local parent directory.
it's like doing 'cd ..'.

Returns bool

TRUE on success, FALSE on failure.


chDir

public bool chDir( string $directory )

  Changes remote directory.

Parameter
string $directory
(the directory to go to.)
Returns bool

TRUE on success, FALSE on failure.


localChDir

public bool localChDir( )

  Changes local directory.

Returns bool

TRUE on success, FALSE on failure.


mkDir

public bool mkDir( string $directory )

  Creates a remote directory.
your current working dir won't change [into that directory].

Parameter
string $directory
(the new directory name.)
Returns bool

TRUE on success, FALSE on failure.


localMkDir

public mixed localMkDir( string $directory )

  Creates a local directory.

Parameter
string $directory
(the new directory name.)
Returns mixed

(string (the new directory name) on success, bool FALSE on failure.


rmDir

public bool rmDir( string $directory )

  Removes a remote directory.
the directory must be empty.if you are currently in that directory (current working dir) you better move out.the ftp command for this is RMD.

Parameter
string $directory
(the directory name.)
Returns bool

TRUE on success, FALSE on failure.


rmDirRec

public int rmDirRec( string $directory )

  Removes a remote directory recursively; with all content in it.
if you are currently in that directory (current working dir) you better move out.

Parameter
string $directory
(the directory name.)
Returns int

(1 if everything was removed, 0 if parts were removed, -1 if nothing was removed.)


localRmDir

public bool localRmDir( string $directory )

  Removes a local directory.

Parameter
string $directory
(the directory name.)
Returns bool

TRUE on success, FALSE on failure.


&nList

public array &nList( string $directory )

  Returns a list of files in the given remote directory.
2do: does it return directories too? how about file- and dirlinks?are the values relative or absolute?

Parameter
string $directory
(the directory name.)
Returns array

(vector of filenames.)

Throws bool FALSE

localNlist

public mixed localNlist( string $directory )

  Returns a list of files in the given local directory.

Parameter
string $directory
(the directory name.)
Returns mixed

(an array (vector) of filenames on success, bool FALSE on failure.


&rawList

public mixed &rawList( string $directory, [ string $parse ] )

  Returns a detailed list of files in the given remote directory.
executes the FTP LIST command.if param $parse is TRUE, the return value is a vector holding a hash.each file is represented by a hash inside the vector. for details seeparseRawList().if param $parse is FALSE, the return value is a vector holding stringswith the unparsed information. use $this->sysType() to do something on your own.or better implement the missing functionality into your favorite ftp class!whatever! do something! don't just sit here and stare at these lines! and giveme some of your pizza! *yummy* :-)

Parameter
string $directory
(the directory name.)
string $parse = >>TRUE<<
(default is TRUE, see above.)
Returns mixed

(an array (vector) see above, bool FALSE on failure.


&parseRawList

public array &parseRawList( array &$rawList )

  parses the given $rawList.
i really don't see why the return of an ftp LIST command has never been standardized.see header documentation.different ftp servers return a different string format. please report here what you know.Serv-U version 2.4"-rw-r--r-- 1 user group 117 Sep 17 10:38 welcomeMessage.txt"comets ftpd (some linux ftpd, i should check that.)"drwxr-xr-x 3 root root 4096 Jan 25 2001 ircd"Serv-U and the linux one give the same output (one space different). that's pretty good.description of the parts:drwxr-xr-x => the first character can be a 'd' or a '-'. d means the 'file' is a directory,- means it is a file.3 => this integer is a number from 1 to n. if the 'file' is a file, it's alwaysset to 1. if it is a directory, it is 2-n. it is the number of (recursive)subdirectories plus the current directory plus 1. so a '3' means this dirhas exactly one subdir.root => the owner user.root => the owner group.4096 => the file size in bytes.Jan 25 2001 => this is the datetime in some strange format and with missing information.if the file has changed this year for the last time, we get month day andhour/minute. if it was in a previous year, we get month day and the year.anyway we never get the seconds. this makes it harder/more buggy tosynchronize files.ircd => the file/directory name (whatever it is). i've read about problems if the nameshave spaces in there. my suggestion: don't use spaces at all.the return array may have the following keys, depending on the ftpserver-os:'name' => 'someshit.txt' //file or directory name'size' => 4096 //bytes'date' => '2001/09/07 08:23' //or '2001/09/07'. see above.'attr' => 'drwxr-xr-x' //(directory yes/no, user rights, group rights, world rights)'type' => [dir|file] //can't tell if it's a link :('dirno' => [1-n] //the directory number, details see above.'user' => 'root' //the owner user. on windows this doesn't mean much.'group' => 'root' //the owner group. on windows this doesn't mean much.

Parameter
array &$rawList
Returns array

(see above)

Throws bool FALSE if not capable = we did not get the format above.

&localRawList

public array &localRawList( string $localDir )

  Returns a detailed list of files in the given local directory.
in difference to rawList() the returned value is always 'parsed'. everything elsewould make no sense.

Parameter
string $localDir
Returns array

(vector holding hashes)


sysType

public string sysType( [ string $useCache ] )

  Returns the system type identifier of the remote FTP server.
executes the FTP SYST command.the name returned shall be one listed in the assigned numbers document. seethe kb file operatingSystemNames.txt (about 130 are listed).my Serv-U ftpd on windows returns 'UNIX', exactly like some ftpd on my linuxbox does. and because they give similar unix-like output on the LIST command(see parseRawList()) i think that's what it's for. if you want to know theoperating system you better use something else than ftp.

Parameter
string $useCache = >>TRUE<<
default is TRUE. if we should use the cached information if available.
Returns string

Throws bool FALSE

pasv

public bool pasv( bool $param )

  Turns passive mode on or off.
if $param is TRUE, passive mode will be activated, deactivated otherwise.in passive mode, data connections are initiated by the client, rather than by the server.

Parameter
bool $param
Returns bool

TRUE on success, FALSE on failure.


get

public bool get( string $localFile, string $remoteFile, [ string $mode ] )

  Downloads a file from the FTP server.
retrieves $remoteFile from the FTP server, and saves it to $localFile locally. Thetransfer mode specified must be either FTP_ASCII or FTP_BINARY.caution: overwrites any existing file.

Parameter
string $localFile
string $remoteFile
string $mode = >>NULL<<
(use constant, one of FTP_ASCII or FTP_BINARY. if not given $this->_transferMode is used.)
Returns bool

TRUE on success, FALSE on failure.


fGet

public bool fGet( int $fp, string $remoteFile, [ string $mode ] )

  Downloads a file from the FTP server and saves to an open file.
retrieves remote_file from the FTP server, and writes it to the given file pointer, fp.The transfer mode specified must be either FTP_ASCII or FTP_BINARY.

Parameter
int $fp
er)
string $remoteFile
string $mode = >>NULL<<
(use constant, one of FTP_ASCII or FTP_BINARY. if not given $this->_transferMode is used.)
Returns bool

TRUE on success, FALSE on failure.


put

public bool put( string $localFile, string $remoteFile, [ string $mode ] )

  Uploads a file to the FTP server.
stores local_file on the FTP server, as remote_file. The transfer mode specifiedmust be either FTP_ASCII or FTP_BINARY.caution: overwrites any existing file.

Parameter
string $localFile
string $remoteFile
string $mode = >>NULL<<
(use constant, one of FTP_ASCII or FTP_BINARY. if not given $this->_transferMode is used.)
Returns bool

TRUE on success, FALSE on failure.


fPut

public bool fPut( int $fp, string $remoteFile, [ string $mode ] )

  Uploads from an open file to the FTP server.
uploads the data from the file pointer fp until end of file. The results are storedin remote_file on the FTP server. The transfer mode specified must be either FTP_ASCIIor FTP_BINARY.

Parameter
int $fp
er)
string $remoteFile
string $mode = >>NULL<<
(use constant, one of FTP_ASCII or FTP_BINARY. if not given $this->_transferMode is used.)
Returns bool

TRUE on success, FALSE on failure.


fileExists

public bool fileExists( string $remoteFile )

  tells if the given file exists on the server.

Parameter
string $remoteFile
Returns bool

TRUE if it does, FALSE if it does not

Throws null if we can't tell (error, no permission)

size

public int size( string $remoteFile )

  Returns the size of the given remote file.
caution: Not all servers support this feature. see header documentation.please report here which server do/don't support it. thanx.executes the FTP SIZE command.

Parameter
string $remoteFile
Returns int

the file size (in bytes i guess)

Throws bool FALSE on error or if not supported by server.
See Also localSize()

localSize

public int localSize( string $localFile )

  Returns the size of the given local file.

Parameter
string $localFile
Returns int

the file size (in bytes i guess)

Throws bool FALSE on error
See Also size()

lastMod

public int lastMod( string $remoteFile )

  Returns the last modified time of the given remote file.
caution: Not all servers support this feature. see header documentation.note: does not work with directories.executes the FTP MDTM command.

Parameter
string $remoteFile
Returns int

unix timestamp

Throws bool FALSE on error or if not supported by server.
See Also localLastMod()

localLastMod

public int localLastMod( string $localFile )

  Returns the last modified time of the given local file.

Parameter
string $localFile
Returns int

unix timestamp

Throws bool FALSE on error
See Also lastMod()

rename

public bool rename( string $remoteFile, string $newRemoteFile )

  Renames a file on the ftp server.

Parameter
string $remoteFile
string $newRemoteFile
Returns bool

TRUE on success, FALSE on failure.

See Also localRename()

localRename

public bool localRename( string $localFile, string $newLocalFile )

  Renames a local file.

Parameter
string $localFile
string $newLocalFile
Returns bool

TRUE on success, FALSE on failure.

See Also rename()

delete

public bool delete( string $remoteFile )

  Deletes a file on the ftp server.

Parameter
string $remoteFile
Returns bool

TRUE on success, FALSE on failure.

See Also localDelete()

localDelete

public bool localDelete( string $localFile )

  Deletes a local file.

Parameter
string $localFile
Returns bool

TRUE on success, FALSE on failure.

See Also delete()

site

public void site( string $command )

  Sends a SITE command to the server.
sends the command $command to the FTP server. SITE commands are not standardized,and vary from server to server. They are useful for handling such things as filepermissions and group membership.

Parameter
string $command
Returns void


quit

public void quit( )

  Closes the FTP connection.

Returns void


Private Method Details

synchronizeFile

private void synchronizeFile( string $localFile, $remoteFile, string $direction )

 

Parameter
string $localFile
(one of [both|up|down])
$remoteFile
Warning: documentation is missing.
string $direction
Warning: documentation is missing.
Returns void


synchronizeDir

private void synchronizeDir( int $localDir, $remoteDir, integer $depth, string $direction )

 

Parameter
int $localDir
(how many directory levels we should follow. 0 = none. -1 = unlimited. default is 0 (more security).)
$remoteDir
Warning: documentation is missing.
integer $depth
Warning: documentation is missing.
string $direction
Warning: documentation is missing.
Returns void


isConnected

private void isConnected( )

 

Warning: documentation is missing.

Returns void


localRmDirRec

private void localRmDirRec( )

 

Warning: documentation is missing.

Returns void


localExists

private void localExists( )

 

Warning: documentation is missing.

Returns void


dirExists

private void dirExists( )

 

Warning: documentation is missing.

Returns void


localDirExists

private void localDirExists( )

 

Warning: documentation is missing.

Returns void


set_perm

private void set_perm( $obj, $num )

 

Warning: documentation is missing.

Parameter
$obj
Warning: documentation is missing.
$num
Warning: documentation is missing.
Returns void


get_perm

private void get_perm( $obj, string $type )

 

Warning: documentation is missing.

Parameter
$obj
Warning: documentation is missing.
string $type
Warning: documentation is missing.
Returns void


ftp_file_exists

private void ftp_file_exists( $pathname )

 

Warning: documentation is missing.

Parameter
$pathname
Warning: documentation is missing.
Returns void


Public Field Details

$_isConnected

public string $_isConnected

>>FALSE<<

tells if we're connected to a server or not.

See Also isConnected()

$host

public string $host

>><<

the host to connect to.


$port

public integer $port

>>21<<

the port to connect to. default is 21.


$anonymous

public string $anonymous

>>TRUE<<

if connection should be made anonymous or not.

See Also $username, $password

$username

public string $username

>><<

if not connecting anonymous this username will be sent.

See Also $anonymous, $password

$password

public string $password

>><<

if not connecting anonymous this password will be sent.

See Also $anonymous, $username

$transferMode

public string $transferMode

>>FTP_ASCII<<

the transfer mode. one of [FTP_ASCII|FTP_BINARY]. default is binary.
i thought it's too dangerous (with subclassing) to just call it 'mode'.again: make sure these 2 constants are set: FTP_ASCII and FTP_BINARY.


Private Field Details

$_Bs_Date

private object [unknown] $_Bs_Date

>><<

reference to the globally used bs_date class. pseudostatic.


$_remotePath

private string $_remotePath

>><<

also known as cwd (current working dir).

See Also $_remoteRootPath, $_localPath

$_localPath

private string $_localPath

>><<

current local path

See Also $_remoteRootPath, $_remotePath

$_sysType

private string $_sysType

>><<

cached output of sysType()

See Also sysType()

$_remoteRootPath

private unknown $_remoteRootPath

>><<



Private Constant Details

BS_FTPCLIENT_VERSION

define( BS_FTPCLIENT_VERSION, >>4.0.$x$<< )
Case: default: case sensitive




Packageindex Classtrees Modulegroups Elementlist Report XML Files
PHPDoc 1.0beta