FtpConnection
in package
Class FtpConnection Simple FTP protocol implementation.
Tags
Table of Contents
Properties
- $connection : resource
- $error : string
- $last_message : string
- $pasv : array{ip: string, port: int}
Methods
- __construct() : mixed
- Create a new FTP connection.
- chdir() : bool
- Changes to a directory (chdir) via the ftp connection
- check_response() : bool
- Reads the response to the command from the server
- chmod() : bool
- Changes a files attributes (chmod)
- close() : bool
- Close the ftp connection
- connect() : void
- Connects to a server
- create_dir() : bool
- Creates a new directory on the server
- create_file() : bool
- Creates a new file on the server
- detect_path() : array<string|int, mixed>
- Detects the current path
- list_dir() : string|bool
- Generates a directory listing for the current directory
- locate() : string|bool
- Determines the current directory we are in
- passive() : bool
- Used to create a passive connection
- unlink() : bool
- Deletes a file
Properties
$connection
public
resource
$connection
Holds the connection response
$error
public
string
$error
Holds any errors
$last_message
public
string
$last_message
Holds the last message from the server
$pasv
public
array{ip: string, port: int}
$pasv
= []
Contains information about passive mode if used.
Methods
__construct()
Create a new FTP connection.
public
__construct(string|null $ftp_server[, int $ftp_port = 21 ][, string $ftp_user = 'anonymous' ][, string $ftp_pass = 'ftpclient@simplemachines.org' ]) : mixed
..
Parameters
- $ftp_server : string|null
-
The server to connect to
- $ftp_port : int = 21
-
The port to connect to
- $ftp_user : string = 'anonymous'
-
The username
- $ftp_pass : string = 'ftpclient@simplemachines.org'
-
The password
chdir()
Changes to a directory (chdir) via the ftp connection
public
chdir(string $ftp_path) : bool
Parameters
- $ftp_path : string
-
The path to the directory we want to change to
Return values
bool —Whether or not the operation was successful
check_response()
Reads the response to the command from the server
public
check_response(int|string|array<string|int, mixed> $desired) : bool
Parameters
- $desired : int|string|array<string|int, mixed>
-
The desired response
Return values
bool —Whether or not we got the desired response
chmod()
Changes a files attributes (chmod)
public
chmod(string $ftp_file, int|string $chmod) : bool
Parameters
- $ftp_file : string
-
The file to CHMOD
- $chmod : int|string
-
The value for the CHMOD operation
Return values
bool —Whether or not the operation was successful
close()
Close the ftp connection
public
close() : bool
Return values
bool —Always returns true
connect()
Connects to a server
public
connect(string $ftp_server[, int $ftp_port = 21 ][, string $ftp_user = 'anonymous' ][, string $ftp_pass = 'ftpclient@simplemachines.org' ]) : void
Parameters
- $ftp_server : string
-
The address of the server
- $ftp_port : int = 21
-
The port
- $ftp_user : string = 'anonymous'
-
The username
- $ftp_pass : string = 'ftpclient@simplemachines.org'
-
The password
create_dir()
Creates a new directory on the server
public
create_dir(string $ftp_dir) : bool
Parameters
- $ftp_dir : string
-
The name of the directory to create
Return values
bool —Whether or not the operation was successful
create_file()
Creates a new file on the server
public
create_file(string $ftp_file) : bool
Parameters
- $ftp_file : string
-
The file to create
Return values
bool —Whether or not the file was created successfully
detect_path()
Detects the current path
public
detect_path(string $filesystem_path[, string $lookup_file = null ]) : array<string|int, mixed>
Parameters
- $filesystem_path : string
-
The full path from the filesystem
- $lookup_file : string = null
-
The name of a file in the specified path
Return values
array<string|int, mixed> —An array of detected info - username, path from FTP root and whether or not the current path was found
list_dir()
Generates a directory listing for the current directory
public
list_dir([string $ftp_path = '' ][, bool $search = false ]) : string|bool
Parameters
- $ftp_path : string = ''
-
The path to the directory
- $search : bool = false
-
Whether or not to get a recursive directory listing
Return values
string|bool —The results of the command or false if unsuccessful
locate()
Determines the current directory we are in
public
locate(string $file[, string $listing = null ]) : string|bool
Parameters
- $file : string
-
The name of a file
- $listing : string = null
-
A directory listing or null to generate one
Return values
string|bool —The name of the file or false if it wasn't found
passive()
Used to create a passive connection
public
passive() : bool
Return values
bool —Whether the passive connection was created successfully
unlink()
Deletes a file
public
unlink(string $ftp_file) : bool
Parameters
- $ftp_file : string
-
The file to delete
Return values
bool —Whether or not the operation was successful