Jump to: navigation, search

Table of Contents >> Application Reference

The FTPD Application Program Interface allows the user to run an FTP server. It consists of two parts:

1. User Interface:
The user interface allows the user to start/stop the FTP server to allow/stop remote FTP clients to connect and exchange files with the host.
2. File System Interface:
The file system interface allows the FTP server to interact with the operating system's file system to store and retrieve files for example.

User Interface

Three calls are provided in the FTPD User Interface.

1. tfNgFtpdUserStart()
The User calls tfNgFtpdUserStart() to open an FTP server socket and start listening for incoming connections. tfNgFtpdUserStart() can be either blocking or non-blocking, as specified by its blockingState parameter.
Blocking Mode
In blocking mode, tfNgFtpdUserStart() should be called from a task. tfNgFtpdUserStart() will not return unless an error occurs, and will block and wait for incoming connections, and execute the FTP server code in the context of the calling task. Choose the blocking mode, if you are using an RTOS/Kernel.
Non-Blocking Mode
In non-blocking mode, tfNgFtpdUserStart() will return immediately after listening for incoming connections. It is the user's responsibility to then call tfFtpdUserExecute() periodically to execute the FTP server code. Choose the non-blocking mode if you do not have an RTOS/Kernel.
2. tfFtpdUserExecute()
If the user had called tfNgFtpdUserStart() in non-blocking mode, then the user needs to call tfFtpdUserExecute() periodically. If the user had called tfNgFtpdUserStart() in blocking mode, then there is no need to call tfFtpdUserExecute().
3. tfFtpdUserStop()
The user calls tfFtpdUserStop() to close the FTP server socket and kill all existing FTP connections.

Using SSL/TLS with the FTP Server

The Treck FTP server supports the use of SSL/TLS. Use tfFtpdSslUserStart() to enable and configure SSL/TLS for the Treck FTP server.

Example Code

int tfxStartFtpdOverSsl (void)
    ttUserGenericUnion reserved;
    int sslSessionId;
    int errorCode;
    int numbConnections;
/* Initialize temp variables */
    reserved.genIntParm = 0;
    errorCode = TM_ENOERROR;
    numbConnections = 10;
/* Create an SSL session for the server */
    sslSessionId = tfSslNewSession( "servscert",
                                    TM_SSL_VERSION_30 | TM_SSL_VERSION_31,
                                    0 );
/* Start the Server with SSL enabled */
    errorCode = tfFtpdSslUserStart( TM_FS_ALLCMND_MASK, /* fileFlags */
                                    numbConnections,    /* maxConnections */
                                    2,                  /* maxBackLog */
                                    300,                /* idleTimeout */
                                    TM_BLOCKING_OFF,    /* blockingState */
                                    0,                  /* flags */
                                    TM_FTPD_SSL_ALLOWED,/* sslCtrlPermissions */
                                    TM_FTPD_SSL_ALLOWED,/* sslDataPermissions */
                                    sslSessionId,       /* ftpdSslSessionId */
                                    reserved );         /* reserved */
    return errorCode;

Function Calls

File System Interface

Entry points from the FTP server to the file system:

tfFSChangeDir() Change current working directory.
tfFSChangeParentDir() Change current working directory to parent Directory.
tfFSCloseDir() Close a directory that we had opened earlier.
tfFSCloseFile() Close a file.
tfFSDeleteFile() Delete a file.
tfFSGetNextDirEntry() Get the next directory entry in the directory open with tfFSOpenDir(), either a long listing of the directory entry (including volumes, sub directories, and file names), or a short listing of the directory (file name only), depending on how the directory was open.
tfFSGetUniqueFileName() Given a file name, return a unique file name in the current directory (i.e, if the file name already exists, make up a new name that is unique in the current directory.)
tfFSGetWorkingDir() Get user working directory.
tfFSMakeDir() Create specified directory.
tfFSOpenDir() Open specified directory, or directory corresponding to a specified pattern to allow getting a long or short listing of the directory or of the directory entries matching the specified pattern.
tfFSOpenFile() Open a file (creating it if it does not exist), for read, write, or append, specifying type (ASCII, or binary), structure (stream, or record).
tfFSReadFile() Read n bytes from a file into a buffer.
tfFSReadFileRecord() Read a record from a file up to n bytes. Indicates whether EOR has been reached.
tfFSRemoveDir() Remove specified directory
tfFSRenameFile() Rename a file.
tfFSStructureMount() Mount the user to a new file system data structure.
tfFSSystem() Return the system name.
tfFSUserAllowed() Indicates whether a specified user is allowed on the system.
tfFSUserLogin() Login a user if password is valid.
tfFSUserLogout() Logout a user.
tfFSWriteFile() Write some bytes from a buffer to a file.
tfFSWriteFileRecord() Write a record from a buffer to a file.

Note Note: File system calls for the FTP server can be found on the File System Interface page.

Table of Contents >> Application Reference