The FileSyncTask class copies files either to or from a remote host, or locally on the current host.

It allows rsync to transfer the differences between two sets of files across the network connection, using an efficient checksum-search algorithm.

There are 4 different ways of using FileSyncTask:

  1. For copying local files.
  2. For copying from the local machine to a remote machine using a remote shell program as the transport (ssh).
  3. For copying from a remote machine to the local machine using a remote shell program.
  4. For listing files on a remote machine.

This is extended from Federico's original code, all his docs are kept in here below.

author Federico Cargnelutti
author Anton Stöckl
version $Revision$
package phing.tasks.ext
see \global\http://svn.fedecarg.com/repo/Phing/tasks/ext/FileSyncTask.php
example http://fedecarg.com/wiki/FileSyncTask
copyright 2001,2002 THYRELL. All rights reserved

 Methods

Executes the rsync command and returns the exit code.

executeCommand() : int

Exceptions

\BuildException

Returns

intReturn code from execution.

Returns the rsync command line options.

getCommand() : string

Returns

string

Returns the textual description of the task

getDescription() : string
Inherited
inherited_from \Task::getDescription()

Returns

stringThe text description of the task

Returns an error message based on a given error code.

getErrorMessage(int $code) : null | string

Parameters

$code

int

Error code

Returns

nullstring

Returns the location within the buildfile this task occurs.

getLocation() : \Location
Inherited

Used by BuildException to give detailed error messages.

inherited_from \Task::getLocation()

Returns

\LocationThe location object describing the position of this task within the buildfile.

Returns the owning target of this task.

getOwningTarget() : \Target
Inherited
inherited_from \Task::getOwningTarget()

Returns

\TargetThe target object that owns this task

Returns a reference to current project

getProject() : \Project
Inherited
inherited_from \ProjectComponent::getProject()
inherited_from \Task::getProject()

Returns

\ProjectReference to current porject object

Returns the wrapper object for runtime configuration

getRuntimeConfigurableWrapper() : \RuntimeConfigurable
Inherited
inherited_from \Task::getRuntimeConfigurableWrapper()

Returns

\RuntimeConfigurableThe wrapper object used by this task

Returns the name of task, used only for log messages

getTaskName() : string
Inherited
inherited_from \Task::getTaskName()

Returns

stringName of this task

Returns the name of the task under which it was invoked, usually the XML tagname

getTaskType() : string
Inherited
inherited_from \Task::getTaskType()

Returns

stringThe type of this task (XML Tag)

Called by the parser to let the task initialize properly.

init() 
Inherited

Should throw a BuildException if something goes wrong with the build

This is abstract here, but may not be overloaded by subclasses.

inherited_from \Task::init()

Exceptions

\BuildException

Provides a project level log event to the task.

log(string $msg, integer $level) 
Inherited
see \global\BuildEvent
see \global\BuildListener
inherited_from \Task::log()

Parameters

$msg

string

The message to log

$level

integer

The priority of the message

Phing's main method.

main() : void

Wraps the executeCommand() method.

Configure this task if it hasn't been done already.

maybeConfigure() 
Inherited
inherited_from \Task::maybeConfigure()

Perfrom this task

perform() 
Inherited
inherited_from \Task::perform()

Makes backups into hierarchy based in $dir.

setBackupDir(string $dir) : void

Parameters

$dir

string

dir

This changes the way rsync checks if the files have been changed and are in need of a transfer.

setChecksum(boolean $checksum) : void

Without this option, rsync uses a "quick check" that (by default) checks if each file’s size and time of last modification match between the sender and receiver. This option changes this to compare a 128-bit checksum for each file that has a matching size.

Parameters

$checksum

boolean

Tells rsync to delete extraneous files from the receiving side, but only for the directories that are being synchronized.

setDelete(boolean $delete) : void

Files that are excluded from transfer are also excluded from being deleted.

Parameters

$delete

boolean

Sets a textual description of the task

setDescription(string $desc) 
Inherited
inherited_from \Task::setDescription()

Parameters

$desc

string

The text describing the task

Sets the destination directory.

setDestinationDir(string $dir) : void

If the option remotehost is not included in the build.xml file, rsync will point to a local directory instead.

Parameters

$dir

string

This makes rsync perform a trial run that doesn’t make any changes (and produces mostly the same output as a real run).

setDryRun(boolean $dryRun) : void

It is most commonly used in combination with the -v, --verbose and/or -i, --itemize-changes options to see what an rsync command is going to do before one actually runs it.

Parameters

$dryRun

boolean

Exclude files matching patterns from $file, Blank lines in $file and lines starting with ';' or '#' are ignored.

setExcludeFile(string $file) : void

Parameters

$file

string

Sets the identity file for public key transfers.

setIdentityFile(string $identity) : void

Parameters

$identity

string

location of ssh identity file

Requests a simple itemized list of the changes that are being made to each file, including attribute changes.

setItemizeChanges($itemizeChanges) : void

Parameters

$itemizeChanges

Sets the location within the buildfile this task occurs.

setLocation(\Location $location) 
Inherited

Called by the parser to set location information.

inherited_from \Task::setLocation()

Parameters

$location

\Location

The location object describing the position of this task within the buildfile.

Sets the command options.

setOptions(string $options) : void

Parameters

$options

string

Sets the owning target this task belongs to.

setOwningTarget(\Target $target) 
Inherited
inherited_from \Task::setOwningTarget()

Parameters

$target

\Target

Reference to owning target

References the project to the current component.

setProject(\Project $project) 
Inherited
inherited_from \ProjectComponent::setProject()
inherited_from \Task::setProject()

Parameters

$project

\Project

The reference to the current project

Sets the remote host.

setRemoteHost(string $host) : void

Parameters

$host

string

This option allows you to provide a password for accessing a remote rsync daemon.

setRemotePass(string $pass) : void

Note that this option is only useful when accessing an rsync daemon using the built in transport, not when using a remote shell as the transport.

Parameters

$pass

string

Allows the user to choose an alternative remote shell program to use for communication between the local and remote copies of rsync.

setRemoteShell(string $shell) : void

Typically, rsync is configured to use ssh by default, but you may prefer to use rsh on a local network.

Parameters

$shell

string

Specifies the user to log in as on the remote machine.

setRemoteUser(string $user) : void

This also may be specified in the properties file.

Parameters

$user

string

Sets the path to the rsync command.

setRsyncPath(string $path) : void

Parameters

$path

string

Sets the wrapper object this task should use for runtime configurable elements.

setRuntimeConfigurableWrapper(\RuntimeConfigurable $wrapper) 
Inherited
inherited_from \Task::setRuntimeConfigurableWrapper()

Parameters

$wrapper

\RuntimeConfigurable

The wrapper object this task should use

Sets the source directory.

setSourceDir(string $dir) : void

Parameters

$dir

string

Sets the name of this task for log messages

setTaskName(string $name) : string
Inherited
inherited_from \Task::setTaskName()

Parameters

$name

string

Returns

stringA string representing the name of this task for log

Sets the type of the task.

setTaskType(string $name) 
Inherited

Usually this is the name of the XML tag

inherited_from \Task::setTaskType()

Parameters

$name

string

The type of this task (XML Tag)

Increases the amount of information you are given during the transfer.

setVerbose(boolean $verbose) : void

By default, rsync works silently. A single -v will give you information about what files are being transferred and a brief summary at the end.

Parameters

$verbose

boolean

Returns a name

getRegisterSlot(string $slotName) 
Inherited
inherited_from \Task::getRegisterSlot()

Parameters

$slotName

string

Sets the isRemoteConnection property.

setIsRemoteConnection(boolean $isRemote) : void

Parameters

$isRemote

boolean

 Properties

 

$backupDir : string

The remote directory is copied to a new directory specified by the user.

 

$checksum : boolean
 

$defaultOptions : string

r - recursive p - preserve permissions K - treat symlinked dir on receiver as dir z - compress l - copy symlinks as symlinks

 

$delete : boolean
 

$description : string
Inherited
inherited_from \Task::$$description
 

$destinationDir : string

For remote targets this must contain user and host, e.g.: user@host:/my/target/dir

 

$dryRun : boolean
 

$excludeFile : string
 

$identityFile : string
 

$isRemoteConnection : boolean
 

$itemizeChanges : boolean
 

$location : \Location
Inherited
inherited_from \Task::$$location
 

$project : \Project
Inherited
inherited_from \ProjectComponent::$$project
inherited_from \Task::$$project
 

$remoteHost : string
 

$remotePass : string
 

$remoteShell : string
 

$remoteUser : string
 

$rsyncPath : string
 

$sourceDir : string

For remote sources this must contain user and host, e.g.: user@host:/my/source/dir

 

$target : \Target
Inherited
inherited_from \Task::$$target
 

$taskName : string
Inherited
inherited_from \Task::$$taskName
 

$taskType : string
Inherited
inherited_from \Task::$$taskType
 

$verbose : boolean

The verbose option set to true will give you information about what files are being transferred and a brief summary at the end.

 

$wrapper : \RuntimeConfigurable
Inherited
inherited_from \Task::$$wrapper