View on GitHub

DSFML

dsfml.network.ftp

A module containing the Ftp class.

class Ftp;
A FTP client.

The Ftp class is a very simple FTP client that allows you to communicate with a FTP server.

The FTP protocol allows you to manipulate a remote file system (list files, upload, download, create, remove, ...).

enum TransferMode: int;
Enumeration of transfer modes.

Binary
Binary mode (file is transfered as a sequence of bytes)

Ascii
Text mode using ASCII encoding.

Ebcdic
Text mode using EBCDIC encoding.

this();
Default Constructor.

DirectoryResponse getWorkingDirectory();
Get the current working directory.

The working directory is the root path for subsequent operations involving directories and/or filenames.





Returns:
Server response to the request.

ListingResponse getDirectoryListing(string directory = "");
Get the contents of the given directory.

This function retrieves the sub-directories and files contained in the given directory. It is not recursive. The directory parameter is relative to the current working directory.





Returns:
Server response to the request.

Response changeDirectory(string directory);
Change the current working directory.

The new directory must be relative to the current one.





Returns:
Server response to the request.

Response connect(IpAddress address, ushort port = 21, Time timeout = Time.Zero);
Connect to the specified FTP server.

The port has a default value of 21, which is the standard port used by the FTP protocol. You shouldn't use a different value, unless you really know what you do.

This function tries to connect to the server so it may take a while to complete, especially if the server is not reachable. To avoid blocking your application for too long, you can use a timeout. The default value, Time::Zero, means that the system timeout will be used (which is usually pretty long).





Params:
IpAddress address Address of the FTP server to connect to.
ushort port Port used for the connection.
Time timeout Maximum time to wait.

Returns:
Server response to the request.

Response connect(string address, ushort port = 21, Time timeout = Time.Zero);
Connect to the specified FTP server.

The port has a default value of 21, which is the standard port used by the FTP protocol. You shouldn't use a different value, unless you really know what you do.

This function tries to connect to the server so it may take a while to complete, especially if the server is not reachable. To avoid blocking your application for too long, you can use a timeout. The default value, Time::Zero, means that the system timeout will be used (which is usually pretty long).





Params:
string address Name or ddress of the FTP server to connect to.
ushort port Port used for the connection.
Time timeout Maximum time to wait.

Returns:
Server response to the request.

Response deleteDirectory(string name);
Remove an existing directory.

The directory to remove must be relative to the current working directory. Use this function with caution, the directory will be removed permanently!





Params:
string name Name of the directory to remove.

Returns:
Server response to the request.

Response deleteFile(string name);
Remove an existing file.

The file name must be relative to the current working directory. Use this function with caution, the file will be removed permanently!





Params:
string name Name of the file to remove.

Returns:
Server response to the request.

Response disconnect();
Close the connection with the server.

Returns:
Server response to the request.

Response download(string remoteFile, string localPath, TransferMode mode = TransferMode.Binary);
Download a file from the server.

The filename of the distant file is relative to the current working directory of the server, and the local destination path is relative to the current directory of your application.





Params:
string remoteFile Filename of the distant file to download.
string localPath Where to put to file on the local computer.
TransferMode mode Transfer mode.

Returns:
Server response to the request.

Response keepAlive();
Send a null command to keep the connection alive.

This command is useful because the server may close the connection automatically if no command is sent.





Returns:
Server response to the request.

Response login();
Log in using an anonymous account.

Logging in is mandatory after connecting to the server. Users that are not logged in cannot perform any operation.





Returns:
Server response to the request.

Response login(string name, string password);
Log in using a username and a password.

Logging in is mandatory after connecting to the server. Users that are not logged in cannot perform any operation.





Params:
string name User name.
string password The password.

Returns:
Server response to the request.

Response parentDirectory();
Go to the parent directory of the current one.

Returns:
Server response to the request.

Response createDirectory(string name);
Create a new directory.

The new directory is created as a child of the current working directory.





Params:
string name Name of the directory to create.

Returns:
Server response to the request.

Response renameFile(string file, string newName);
Rename an existing file.

The filenames must be relative to the current working directory.





Params:
string file File to rename.
string newName New name of the file.

Returns:
Server response to the request.

Response upload(string localFile, string remotePath, TransferMode mode = TransferMode.Binary);
Upload a file to the server.

The name of the local file is relative to the current working directory of your application, and the remote path is relative to the current directory of the FTP server.





Params:
string localFile Path of the local file to upload.
string remotePath Where to put the file on the server.
TransferMode mode Transfer mode.

Returns:
Server response to the request.

class DirectoryResponse: dsfml.network.ftp.Ftp.Response;
Specialization of FTP response returning a directory.

string getDirectory();
Get the directory returned in the response.

Returns:
Directory name.

class ListingResponse: dsfml.network.ftp.Ftp.Response;
Specialization of FTP response returning a filename lisiting.

const(string[]) getFilenames();
Return the array of directory/file names.

Returns:
Array containing the requested listing.

class Response;
Define a FTP response.

enum Status: int;
Status codes possibly returned by a FTP response.

const string getMessage();
Get the full message contained in the response.

Returns:
The response message.

const Status getStatus();
Get the status code of the response.

Returns:
Status code.

const bool isOk();
Check if the status code means a success.

This function is defined for convenience, it is equivalent to testing if the status code is < 400.





Returns:
True if the status is a success, false if it is a failure.