4.7. FtpClient Class

Note: This class is not available with the PO_NO_NETWORK parse option.

The FtpClient class allows Qore programs to communicate with FTP servers. The constructor takes an optional URL with the following format:

[(ftp|ftps)://][username[:password]@]hostname[:port]

If the URL is not set with the constructor, then the connection parameters must be set with the FtpClient::set*() methods. At the very minimum the hostname must be set. If any path name is given in the URL, it is ignored. See the following table for default URL parameters.

Table 4.229. FtpClient::constructor() Default URL Parameters

Field

Default Value

protocol

ftp (unencrypted)

username

anonymous

password

qore@nohost.com

port

21


Once the URL (at least the hostname) has been set, any method requiring a connection will make an implicit call to FtpClient::connect() to attempt to connect and login to the FTP server before executing the method.

Objects of this class are capable of making encrypted FTPS connections according to RFC-4217. TLS/SSL encrypted control and data connection will be attempted if the protocol is set to 'ftps' or the FtpClient::setSecure() method is called before connecting.

Note that 'sftp', or FTP over ssh, is not supported with this class; FTPS is an extension of the FTP protocol to allow for secure connections; while 'sftp' is FTP over an encrypted ssh connection. For sftp and ssh support, use the ssh2 module.

When a data connection is required, by default the following modes are tried in series: EPSV (Extended Passive Mode), PASV (Passive Mode), and PORT (Port mode). If the FTP server does not support one of these methods, or network conditions do not allow a data connection of any of these types to be established, then an exception is thrown.

To manually control which modes are tried, see the FtpClient::setModeEPSV(), FtpClient::setModePASV(), and FtpClient::setModePORT() methods.

This class supports posting network events to a Queue, either events on the control or data channels or both can be monitored. See Event Handling for more information.

The events raised by this object are listed in the following table:

Table 4.230. FtpClient Events

Name

Value

Description

EVENT_FTP_SEND_MESSAGE

9

Raised immediately before an FTP control message is sent.

EVENT_FTP_MESSAGE_RECEIVED

10

Raised when an FTP reply is received on the control channel.


Table 4.231. FtpClient Method Overview

Method

Except?

Description

FtpClient::constructor()

FtpClient::constructor(string $url)

Y

Creates object and optionally initializes URL

FtpClient::destructor()

N

Destroys the object.

FtpClient::copy()

Y

Throws an exception to prevent copying of objects this class.

nothing FtpClient::connect()

Y

Connects and logs in to FTP server

nothing FtpClient::disconnect()

N

Disconnects from the FTP server.

nothing FtpClient::setSecure(softbool $secure = True)

Y

Make an FTPS connection to the server on the next connect if the argument is True.

nothing FtpClient::setInsecure()

Y

Make a non-encrypted connection to the server on the next connect.

nothing FtpClient::setInsecureData()

Y

Make a non-encrypted data connection to the server on the next connect even if the control connection is secure.

bool FtpClient::isSecure()

N

Returns True if the control connection is a secure TLS/SSL connection.

bool FtpClient::isDataSecure()

N

Returns True if the data connections are secure TLS/SSL connections.

*string FtpClient::getSSLCipherName()

N

Returns the name of the cipher for an encrypted connection or NOTHING if no encrypted connection has been established.

*string FtpClient::getSSLCipherVersion()

N

Returns the version string of the cipher for encrypted connections or NOTHING if no encrypted connection has been established.

*string FtpClient::verifyPeerCertificate()

N

Returns a string code giving the result of verifying the remote certificate or NOTHING if no encrypted connection has been established.

nothing FtpClient::setModeAuto()

N

Sets the object to automatically try to negotiate the data connections in EPSV, PASV, and PORT modes, in this order.

nothing FtpClient::setModeEPSV()

N

Sets the object to only try to make data connections using EPSV (RFC-2428 extended passive) mode.

nothing FtpClient::setModePASV()

N

Sets the object to only try to make data connections using PASV (RFC-959 passive) mode.

nothing FtpClient::setModePORT()

N

Sets the object to only try to make data connections using PORT mode.

any FtpClient::list()

*string FtpClient::list(string $path)

Y

Gets a list of files from the FTP server in the server's long format; returns NOTHING if the path cannot be found.

*string FtpClient::nlst()

*string FtpClient::nlst(string $path)

Y

Gets a list of file names from the FTP server; returns NOTHING if the path cannot be found.

string FtpClient::pwd()

Y

Returns the server-side current working directory.

nothing FtpClient::cwd(string $dir)

Y

Changes the current working directory on the server.

nothing FtpClient::get(string $remote_file)

nothing FtpClient::get(string $remote_file, string $local_file)

Y

Gets a file from the FTP server and stores it on the local filesystem; if any errors occur, an exception is thrown..

binary FtpClient::getAsBinary(string $remote_file)

Y

Gets a file from the FTP server and returns it as a binary value.

string FtpClient::getAsString(string $remote_file)

Y

Gets a file from the FTP server and returns it as a string.

nothing FtpClient::put(string $local_file)

nothing FtpClient::put(string $local_file, string $remote_file)

Y

Transfers a file to the FTP server; if any errors occur, an exception is thrown.

nothing FtpClient::putData(data $file_data, string $remote_file_name)

Y

Transfers a data to the FTP server and saves it as a file on the remote machine; if any errors occur, an exception is thrown.

nothing FtpClient::del(string $remote_file)

Y

Deletes a file from the FTP server

nothing FtpClient::mkdir(string $remote_dir)

Y

Creates a directory on the FTP server

nothing FtpClient::rmdir(string $remote_dir)

Y

Removes a directory on the FTP server

nothing FtpClient::rename(string $from, string $to)

Y

Renames/moves a file or directory; if any errors occur, an exception is thrown.

nothing FtpClient::setUserName(string $user)

N

Sets the user name to use

nothing FtpClient::setPassword(string $pass)

N

Sets the password to use

nothing FtpClient::setHostName(string $host)

N

Sets the hostname to connect to

nothing FtpClient::setPort(softint $port)

Y

Sets the port to connect to; throws an exception if the port is <= 0.

nothing FtpClient::setURL(string $url)

Y

Sets the URL

*string FtpClient::getUserName()

N

Gets the current user name or NOTHING if not yet set.

*string FtpClient::getPassword()

N

Gets the current password or NOTHING if not yet set.

*string FtpClient::getHostName()

N

Gets the current hostname or NOTHING if not yet set.

int FtpClient::getPort()

N

Gets the current port number.

string FtpClient::getURL()

N

Gets the current FTP URL.

nothing FtpClient::setEventQueue()

nothing FtpClient::setEventQueue(Queue $queue)

N

Sets a Queue object to receive socket and FtpClient events on both the data and control connections. Calling with no argument clears the queue.

nothing FtpClient::setDataEventQueue()

nothing FtpClient::setDataEventQueue(Queue $queue)

N

Sets a Queue object to receive socket and FtpClient events on the data connection. Calling with no argument clears the queue.

nothing FtpClient::setControlEventQueue()

nothing FtpClient::setControlEventQueue(Queue $queue)

N

Sets a Queue object to receive socket and FtpClient events on the control connection. Calling with no argument clears the queue.


4.7.1. FtpClient::constructor()

Synopsis

Creates the FtpClient object. It accepts one optional argument that will set the URL for the FTP connection; the path is ignored in the URL, however the username, password, hostname and port are respected; additionally if the protocol is "ftps", the client will attempt to establish a secure connection to the server according to RFC-4217 when the first connection is established.

Prototype

FtpClient::constructor()

FtpClient::constructor(string $url)

Example
my FtpClient $ftp("ftp://user:pass@hostname");

Table 4.232. Arguments for FtpClient::constructor()

Argument

Description

string $url

The URL of the server to connect to; must have at least the hostname to connect to.


Table 4.233. Exceptions Thrown by FtpClient::constructor()

err

desc

UNSUPPORTED-PROTOCOL

Only "ftp" or "ftps" are allowed as the protocol in the URL.

FTP-URL-ERROR

No hostname given in the URL.


4.7.2. FtpClient::destructor()

Synopsis

Destroys the object.

Example
delete $ftp;
Events

EVENT_CHANNEL_CLOSED, EVENT_DELETED

4.7.3. FtpClient::copy()

Synopsis

Throws an exception; objects of this class cannot be copied.

Table 4.234. Exceptions Thrown by FtpClient::copy()

err

desc

FTPCLIENT-COPY-ERROR

Objects of this class cannot be copied.


4.7.4. FtpClient::connect()

Synopsis

Connects to the FTP server and attempts a login; if any errors occur, an exception is thrown.

This method does not need to be called explicitly; connections are established implicitly by all methdods that communicate with FTP servers.

Prototype

nothing FtpClient::connect()

Example
$ftp.connect(); # connects to the URL set in the constructor
Events

EVENT_CONNECTING, EVENT_CONNECTED,EVENT_HOSTNAME_LOOKUP, EVENT_HOSTNAME_RESOLVED, EVENT_START_SSL, EVENT_SSL_ESTABLISHED, EVENT_FTP_SEND_MESSAGE, EVENT_FTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_PACKET_SENT

Table 4.235. Exceptions Thrown by FtpClient::connect()

err

desc

FTP-RESPONSE-ERROR

Invalid response received from FTP server.

FTP-CONNECT-ERROR

Cannot establish connection on data port, no hostname set, FTP server reported an error, etc.

FTP-LOGIN-ERROR

Login denied by FTP server.


4.7.5. FtpClient::disconnect()

Synopsis

Disconnects from an FTP server.

Prototype

nothing FtpClient::disconnect()

Example
$ftp.disconnect();
Events

EVENT_CHANNEL_CLOSED

4.7.6. FtpClient::setSecure()

Synopsis

Make an FTPS connection to the server on the next connect. This method can only be called before a connection is established; if called when a connection has already been established, an exception will be thrown.

Prototype

nothing FtpClient::setSecure(softbool $secure = True)

Example
$ftp.setSecure();

Table 4.236. Arguments for FtpClient::setSecure()

Argument

Description

softbool $secure = True

if True, will try to make an FTPS connection on the next connect, if False, will try to make a cleartext FTP connection on the next connect.


Table 4.237. Exceptions thrown by FtpClient::setSecure()

err

desc

SET-SECURE-ERROR

cannot be called while a control connection has already been established.


4.7.7. FtpClient::setInsecure()

Synopsis

Make a non-encrypted connection to the server on the next connect.

Prototype

nothing FtpClient::setInsecure()

Example
$ftp.setInsecure();

Table 4.238. Exceptions thrown by FtpClient::setInsecure()

err

desc

SET-INSECURE-ERROR

cannot be called while a control connection has already been established.


4.7.8. FtpClient::setInsecureData()

Synopsis

Make a non-encrypted data connection to the server on the next connect even if the control connection is secure.

Prototype

nothing FtpClient::setInsecureData()

Example
$ftp.setInsecureData();

Table 4.239. Exceptions thrown by FtpClient::setInsecureData()

err

desc

SET-INSECUREDATA-ERROR

cannot be called while a control connection has already been established.


4.7.9. FtpClient::isSecure()

Synopsis

Returns True if the control connection is a secure TLS/SSL connection.

Prototype

bool FtpClient::isSecure()

Example
my bool $b = $ftp.isSecure();

Table 4.240. Return Values for FtpClient::isSecure()

Return Type

Description

bool

True if the control connection is encrypted, False if not.


4.7.10. FtpClient::isDataSecure()

Synopsis

Returns True if the data connections are secure TLS/SSL connections.

Prototype

bool FtpClient::isDataSecure()

Example
my bool $b = $ftp.isDataSecure();

Table 4.241. Return Values for FtpClient::isDataSecure()

Return Type

Description

bool

True if data connections are encrypted, False if not.


4.7.11. FtpClient::getSSLCipherName()

Synopsis

Returns the name of the cipher for an encrypted connection.

Prototype

*string FtpClient::getSSLCipherName()

Example
my *string $str = $ftp.getSSLCipherName();

Table 4.242. Return Values for FtpClient::getSSLCipherName()

Return Type

Description

*string

The name of the cipher for an encrypted connection or NOTHING if an excrypted connection has not been established.


4.7.12. FtpClient::getSSLCipherVersion()

Synopsis

Returns the version string of the cipher for encrypted connections.

Prototype

*string FtpClient::getSSLCipherVersion()

Example
my *string $str = $ftp.getSSLCipherVersion();

Table 4.243. Return Values for FtpClient::getSSLCipherVersion()

Return Type

Description

*string

The version string of the cipher for encrypted connections or NOTHING if an excrypted connection has not been established.


4.7.13. FtpClient::verifyPeerCertificate()

Synopsis

Returns a string code giving the result of verifying the remote certificate for secure (FTPS) connections. Return value are the keys described in the X509_VerificationReasons hash constant. This hash can also be used to generate a textual description of the verification result.

Prototype

*string FtpClient::verifyPeerCertificate()

Example
my *string $str = $ftp.verifyPeerCertificate();

Table 4.244. Return Values for FtpClient::verifyPeerCertificate()

Return Type

Description

*string

A string code giving the result of verifying the peer's certificate. No value is returned if a secure connection has not been established.


4.7.14. FtpClient::setModeAuto()

Synopsis

Sets the object to automatically try to negotiate the data connections in EPSV, PASV, and PORT modes, in this order.

Prototype

nothing FtpClient::setModeAuto()

Example
$ftp.setModeAuto();

4.7.15. FtpClient::setModeEPSV()

Synopsis

Sets the object to only try to make data connections using EPSV (RFC-2428 extended passive) mode.

Prototype

nothing FtpClient::setModeEPSV()

Example
$ftp.setModeEPSV();

4.7.16. FtpClient::setModePASV()

Synopsis

Sets the object to only try to make data connections using PASV (RFC-959 passive) mode.

Prototype

nothing FtpClient::setModePASV()

Example
$ftp.setModePASV();

4.7.17. FtpClient::setModePORT()

Synopsis

Sets the object to only try to make data connections using PORT mode.

Prototype

nothing FtpClient::setModePORT()

Example
$ftp.setModePORT();

4.7.18. FtpClient::list()

Synopsis

Gets a string giving the list of files from the FTP server in the server's long format in the current working directory; returns NOTHING if the path cannot be found.

Prototype

*string FtpClient::list()

*string FtpClient::list(string $path)

Example
my *string $str = $ftp.list();
Events

EVENT_FTP_SEND_MESSAGE, EVENT_FTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_PACKET_SENT

Table 4.245. Arguments for FtpClient::list()

Argument

Description

[string $path]

The optional path or argument (filter) to list.


Table 4.246. Return Values for FtpClient::list()

Return Type

Description

*string

The string returned by the server without any translations or processing or NOTHING if the path cannot be found.


Table 4.247. Exceptions Thrown by FtpClient::list()

err

desc

FTP-RECEIVE-ERROR

Incomplete message received on control port.

FTP-LIST-ERROR

FTP server returned an error in response to the LIST command.


4.7.19. FtpClient::nlst()

Synopsis

Gets a list of file names in the current working directory from the FTP server.

Prototype

*string FtpClient::nlst()

*string FtpClient::nlst(string $path)

Example
my *string $str = $ftp.nlst();
Events

EVENT_FTP_SEND_MESSAGE, EVENT_FTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_PACKET_SENT

Table 4.248. Arguments for FtpClient::nlst()

Argument

Description

[string $path]

The optional path or argument (filter) to list.


Table 4.249. Return Values for FtpClient::nlst()

Return Type

Description

*string

The string returned by the server without any translations or processing or NOTHING if the path cannot be found.


Table 4.250. Exceptions Thrown by FtpClient::nlst()

err

desc

FTP-RECEIVE-ERROR

Incomplete message received on control port.

FTP-LIST-ERROR

FTP server returned an error in response to the NSLT command.


4.7.20. FtpClient::pwd()

Synopsis

Returns the server-side current working directory.

Prototype

string FtpClient::pwd()

Example
my string $str = $ftp.pwd();
Events

EVENT_FTP_SEND_MESSAGE, EVENT_FTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_PACKET_SENT

Table 4.251. Return Values for FtpClient::pwd()

Return Type

Description

string

The server-side current working directory.


Table 4.252. Exceptions Thrown by FtpClient::pwd()

err

desc

FTP-RECEIVE-ERROR

Incomplete message received on control port.

FTP-PWD-ERROR

FTP server returned an error to the PWD command.


4.7.21. FtpClient::cwd()

Synopsis

Changes the current working directory on the server.

Prototype

nothing FtpClient::cwd(string $dir)

Example
$ftp.cwd("/pub/gnu");
Events

EVENT_FTP_SEND_MESSAGE, EVENT_FTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_PACKET_SENT

Table 4.253. Arguments for FtpClient::cwd()

Argument

Description

string $dir

The directory to change to.


Table 4.254. Exceptions Thrown by FtpClient::cwd()

err

desc

FTP-RECEIVE-ERROR

Incomplete message received on control port.

FTP-CWD-ERROR

FTP server returned an error to the CWD command.


4.7.22. FtpClient::get()

Synopsis

Gets a file from the FTP server and stores it on the local system. If any errors occur, an exception is thrown.

This method accesses the filesystem, so it is not available if PO_NO_FILESYSTEM is set.

Prototype

nothing FtpClient::get(string $remote_file)

nothing FtpClient::get(string $remote_file, string $local_file)

Example
$ftp.get("file.txt", "/tmp/file-1.txt");
Restrictions

Not available with PO_NO_FILESYSTEM

Events

EVENT_FTP_SEND_MESSAGE, EVENT_FTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_PACKET_SENT

Table 4.255. Arguments for FtpClient::get()

Argument

Description

string $remote_file

The path on the server to the file to get.

[string $local_file]

If given, where to save the local file.


Table 4.256. Exceptions Thrown by FtpClient::get()

err

desc

FTP-RECEIVE-ERROR

Incomplete message received on control port.

FTP-FILE-OPEN-ERROR

Could not create the local file.

FTP-GET-ERROR

There was an error retrieving the file.


4.7.23. FtpClient::getAsBinary()

Synopsis

Gets a file from the FTP server and returns the file's contents as a binary value. For a similar function returning the file's contents as a string, see FtpClient::getAsString(); for a function that will get a remote file and save it on the local filesystem, see FtpClient::get().

Prototype

binary FtpClient::getAsBinary(string $remote_file)

Example
my binary $b = $ftp.getAsBinary("file.bin");
Events

EVENT_FTP_SEND_MESSAGE, EVENT_FTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_PACKET_SENT

Table 4.257. Arguments for FtpClient::getAsBinary()

Argument

Description

string $remote_file

The path on the server to the file to get.


Table 4.258. Return Values for FtpClient::getAsBinary()

Return Type

Description

binary

The file retrieved; if any errors occur an exception is raised.


Table 4.259. Exceptions Thrown by FtpClient::getAsBinary()

err

desc

FTP-RECEIVE-ERROR

Incomplete message received on control port.

FTP-FILE-OPEN-ERROR

Could not create the local file.

FTP-GET-ERROR

There was an error retrieving the file.


4.7.24. FtpClient::getAsString()

Synopsis

Gets a file from the FTP server and returns the file's contents as a string. For a similar function returning the file's contents as a binary, see FtpClient::getAsBinary(); for a function that will get a remote file and save it on the local filesystem, see FtpClient::get().

Prototype

string FtpClient::getAsString(string $remote_file)

Example
my string $str = $ftp.getAsString("file.txt");
Events

EVENT_FTP_SEND_MESSAGE, EVENT_FTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_PACKET_SENT

Table 4.260. Arguments for FtpClient::getAsString()

Argument

Description

string $remote_file

The path on the server to the file to get.


Table 4.261. Return Values for FtpClient::getAsString()

Return Type

Description

string

The file retrieved; if any errors occur an exception is raised.


Table 4.262. Exceptions Thrown by FtpClient::getAsString()

err

desc

FTP-RECEIVE-ERROR

Incomplete message received on control port.

FTP-FILE-OPEN-ERROR

Could not create the local file.

FTP-GET-ERROR

There was an error retrieving the file.


4.7.25. FtpClient::put()

Synopsis

Transfers a file to the FTP server. If any errors occur, an exception is thrown.

This method accesses the filesystem, so it is not available if PO_NO_FILESYSTEM is set.

Prototype

int FtpClient::put(string $local_file)

int FtpClient::put(string $local_file, string $remote_file)

Example
$ftp.put("/tmp/file-1.txt", "file.txt");
Restrictions

Not available with PO_NO_FILESYSTEM

Events

EVENT_FTP_SEND_MESSAGE, EVENT_FTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_PACKET_SENT

Table 4.263. Arguments for FtpClient::put()

Argument

Description

string local_file

The path on the local system of the file to send.

[string $remote_file]

If given, where to save the file on the server.


Table 4.264. Exceptions Thrown by FtpClient::put()

err

desc

FTP-RECEIVE-ERROR

Incomplete message received on control port.

FTP-FILE-OPEN-ERROR

Could not open local file for reading.

FTP-FILE-PUT-ERROR

Could not determine file size of local file (stat() failed).

FTP-PUT-ERROR

An error occurred while sending the file.


4.7.26. FtpClient::putData()

Synopsis

Transfers a data to the FTP server and saves it as a file on the remote machine; if any errors occur, an exception is thrown.

Prototype

nothing FtpClient::putData(data $file_data, string $remote_file_name)

Example
$ftp.putData($str, "file.txt");
Events

EVENT_FTP_SEND_MESSAGE, EVENT_FTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_PACKET_SENT

Table 4.265. Arguments for FtpClient::putData()

Argument

Description

data $file_data

The file data to save on the remote server.

[string $remote_file_name]

The file name on the remote server.


Table 4.266. Exceptions Thrown by FtpClient::putData()

err

desc

FTP-RECEIVE-ERROR

Incomplete message received on control port.

FTP-PUT-ERROR

An error occurred while sending the file.


4.7.27. FtpClient::del()

Synopsis

Deletes a file on the FTP server; if any errors occur, an exception is thrown.

Prototype

nothing FtpClient::del(string $remote_file)

Example
$ftp.del("file-2.txt");
Events

EVENT_FTP_SEND_MESSAGE, EVENT_FTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_PACKET_SENT

Table 4.267. Arguments for FtpClient::del()

Argument

Description

string $remote_file

The path on the server to the file to delete.


Table 4.268. Exceptions Thrown by FtpClient::del()

err

desc

FTP-RECEIVE-ERROR

Incomplete message received on control port.

FTP-DELETE-ERROR

FTP server returned an error to the DELE command.


4.7.28. FtpClient::mkdir()

Synopsis

Creates a directory on the remote FTP server; if any errors occur, an exception is thrown.

Prototype

nothing FtpClient::mkdir(string $remote_dir)

Example
$ftp.mkdir("tmp");
Events

EVENT_FTP_SEND_MESSAGE, EVENT_FTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_PACKET_SENT

Table 4.269. Arguments for FtpClient::mkdir()

Argument

Description

string $remote_dir

The path on the server to the directory to create.


Table 4.270. Exceptions Thrown by FtpClient::mkdir()

err

desc

FTP-RECEIVE-ERROR

Incomplete message received on control port.

FTP-MKDIR-ERROR

FTP server returned an error to the MKD command.


4.7.29. FtpClient::rmdir()

Synopsis

Removes a directory on the remote FTP server; if any errors occur, an exception is thrown.

Prototype

nothing FtpClient::rmdir(string $remote_dir)

Example
$ftp.rmdir("tmp");
Events

EVENT_FTP_SEND_MESSAGE, EVENT_FTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_PACKET_SENT

Table 4.271. Arguments for FtpClient::rmdir()

Argument

Description

string $remote_dir

The path on the server to the directory to delete.


Table 4.272. Exceptions Thrown by FtpClient::rmdir()

err

desc

FTP-RECEIVE-ERROR

Incomplete message received on control port.

FTP-RMDIR-ERROR

FTP server returned an error to the RMD command.


4.7.30. FtpClient::rename()

Synopsis

Renames/moves a file or directory; if any errors occur, an exception is thrown.

Prototype

nothing FtpClient::rename(string $from, string $to)

Example
$ftp.rename("file.txt", "file.txt.orig");
Events

EVENT_FTP_SEND_MESSAGE, EVENT_FTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_PACKET_SENT

Table 4.273. Arguments for FtpClient::rename()

Argument

Description

string $from

The original file path on the server to rename/move.

string $from

The new file path on the server.


Table 4.274. Exceptions Thrown by FtpClient::rename()

err

desc

FTP-RECEIVE-ERROR

Incomplete message received on control port.

FTP-RENAME-ERROR

FTP server returned an error to the RNFR or RNTO commands.


4.7.31. FtpClient::setUserName()

Synopsis

Sets the username for logging in to the FTP server.

Prototype

nothing FtpClient::setUserName(string $user)

Example
$ftp.setUserName("ftp");

Table 4.275. Arguments for FtpClient::setUserName()

Argument

Description

string $user

The username to use when logging in to the FTP server.


4.7.32. FtpClient::setPassword()

Synopsis

Sets the login password for the FTP server to connect to.

Prototype

nothing FtpClient::setPassword(string $pass)

Example
$ftp.setPassword("ftp");

Table 4.276. Arguments for FtpClient::setPassword()

Argument

Description

string $pass

The password to use when logging in to the FTP server.


4.7.33. FtpClient::setHostName()

Synopsis

Sets the hostname value for the FTP server to connect to.

Prototype

nothing FtpClient::setHostName(string $host)

Example
$ftp.setHostName("hostname");

Table 4.277. Arguments for FtpClient::setHostName()

Argument

Description

string $host

The hostname to use when connecting to the FTP server.


4.7.34. FtpClient::setPort()

Synopsis

Sets the control port value (default is 21).

Prototype

nothing FtpClient::setPort(softint $port)

Example
$ftp.setPort(21);

Table 4.278. Arguments for FtpClient::setPort()

Argument

Description

softint $port

The port to use when connecting to the FTP server.


Table 4.279. Exceptions Thrown by FtpClient::setPort()

err

desc

FTPCLIENT-SETPORT-PARAMETER-ERROR

Illegal port number passed as an argument (<= 0).


4.7.35. FtpClient::setURL()

Synopsis

Sets the connection and login parameters based on the URL passed as an argument.

Prototype

nothing FtpClient::setURL(string $url)

Example
$ftp.setURL("ftps://user:pass@host");

Table 4.280. Arguments for FtpClient::setURL()

Argument

Description

string $url

The URL to use to set connection and login parameters for the FTP server.


Table 4.281. Exceptions Thrown by FtpClient::setURL()

err

desc

UNSUPPORTED-PROTOCOL

Only "ftp" is allowed as the protocol in the URL.

FTP-URL-ERROR

No hostname given in the URL.


4.7.36. FtpClient::getUserName()

Synopsis

Retrieves the current username.

Prototype

*string FtpClient::getUserName()

Example
my *string $user = $ftp.getUserName();

Table 4.282. Return Values for FtpClient::getUserName()

Return Type

Description

*string

The current username value.


4.7.37. FtpClient::getPassword()

Synopsis

Retrieves the current login password value for this object.

Prototype

*string FtpClient::getPassword()

Example
my *string $pass = $ftp.getPassword();

Table 4.283. Return Values for FtpClient::getPassword()

Return Type

Description

*string

The current password value.


4.7.38. FtpClient::getHostName()

Synopsis

Retrieves the current hostname value for this object.

Prototype

*string FtpClient::getHostName()

Example
my *string $host = $ftp.getHostName();

Table 4.284. Return Values for FtpClient::getHostName()

Return Type

Description

*string

The current hostname value.


4.7.39. FtpClient::getPort()

Synopsis

Retrieves the current connection port value for this object.

Prototype

int FtpClient::getPort()

Example
my int $port = $ftp.getPort();

Table 4.285. Return Values for FtpClient::getPort()

Return Type

Description

int

The current connection port value.


4.7.40. FtpClient::getURL()

Synopsis

Retrieves the current connection URL string for this object.

Prototype

string FtpClient::getURL()

Example
my string $url = $ftp.getURL();

Table 4.286. Return Values for FtpClient::getURL()

Return Type

Description

string

The current URL value.


4.7.41. FtpClient::setEventQueue()

Synopsis

Sets a Queue object to receive socket and FtpClient events on both the data and control connections.

To remove the event queue and stop monitoring socket events, pass NOTHING to the method. See Event Handling for more information.

To control monitoring of network events on just the data connection or just the control connection, use FtpClient::setDataEventQueue or FtpClient::setControlEventQueue respectively

Prototype

nothing FtpClient::setEventQueue()

nothing FtpClient::setEventQueue(Queue $queue)

Example
$ftp.setEventQueue($queue);

Table 4.287. Arguments for FtpClient::setEventQueue()

Argument

Description

[Queue $queue]

To set the event queue, pass a Queue object; to clear the event queue, pass no argument to the function.


4.7.42. FtpClient::setDataEventQueue()

Synopsis

Sets a Queue object to receive socket and FtpClient events on the data connection when retrieving data from an FTP server.

To remove the event queue and stop monitoring network events, pass NOTHING to the method. See Event Handling for more information.

To control monitoring of network events on just the control connection or on both connections with the same queue, use FtpClient::setControlEventQueue or FtpClient::setEventQueue respectively.

Prototype

nothing FtpClient::setDataEventQueue()

nothing FtpClient::setDataEventQueue(Queue $queue)

Example
$ftp.setDataEventQueue($queue);

Table 4.288. Arguments for FtpClient::setDataEventQueue()

Argument

Description

[Queue $queue]

To set the event queue, pass a Queue object; to clear the event queue, pass no argument to the function.


4.7.43. FtpClient::setControlEventQueue()

Synopsis

Sets a Queue object to receive socket and FtpClient events on both the control connection.

To remove the event queue and stop monitoring network events, pass NOTHING to the method. See Event Handling for more information.

To control monitoring of network events on just the data connection or for both data and control connections simultaneously, use FtpClient::setDataEventQueue or FtpClient::setEventQueue respectively

Prototype

nothing FtpClient::setControlEventQueue()

nothing FtpClient::setControlEventQueue(Queue $queue)

Example
$ftp.setControlEventQueue($queue);

Table 4.289. Arguments for FtpClient::setControlEventQueue()

Argument

Description

[Queue $queue]

To set the event queue, pass a Queue object; to clear the event queue, pass no argument to the function.