naftpsvrapp: FTP Server Example Application

This FTP Server application uses the FTP Server API functions to implement:

1) bidirectional file transfers
2) login username and password validation
3) data session and FTP session closed notification
4) callback function examples for FTP create directory, remove directory and 
   delete files.

This example should work on all development boards.

Note:

This FTP example is used to demonstrate how to write the callback functions
for the various FTP server commands.  Since there is no file system servicing
the FTP server, most of the FTP commands will not work.  

The user can only upload and download one file at a time to the FTP server. 
The size of the file must not be larger than the size of the internal RAM bufffer.

If FTP "put" command with the same file name is issued, the file in the RAM buffer is overwritten.
If FTP "put" command with different file name is issued, the command fails. Please use FTP "delete" 
command to "put" a file with a different name.

The "mkdir" and "rmdir" are there just to demonstrate the usage of callbacks. They don't create or
remove directories, but only store the directory name. If "mkdir" with a different name is issued,
it overwrites the previous directory name.

The "cd" is explicitly forbidden, the change_dir() function always returns an error. The "dir" or "ls" 
are not supported, no callbacks are registered and no information is returned. 

End note


Initialization

Execution of the program starts in applicationStart() which calls
ftp_server_app_init() to initialize the FTP Server data structures,
register the callback functions and start the FTP Server.

The call FSInitialize(2) initializes the FTP Server data structures
to support two concurrent FTP sessions.

The call FSRegisterSTOR(store_data) registers the function
store_data() which is called when an FTP STOR command is handled.
(The STOR command is known as the "put" operation in an FTP client
program.)

The call FSRegisterRETR(retrieve_data) registers the function
retrieve_data() which is called when an FTP RETR command is handled.
(The RETR command is known as the "get" operation in an FTP client
program.)

The call FSRegisterValidation(validate_user) registers the function
validate_users() which is called during the FTP login process to
validate the user.

The call FSRegisterDELE(delete_file) registers the function
delete_file() which is called when an FTP DELE command is handled.

The call FSRegisterMKD(make_dir) registers the function make_dir()
which is called when an FTP MKD command is handled.

The call FSRegisterRMD(remove_dir) registers the function
remove_dir() which is called when an FTP RMD command is handled.

The call FSRegisterCWD(change_dir) registers the function
change_dir() which is called when FTP CWD command is handled. 

The call FSRegisterControlClose(FTP_session_closed) registers the
function FTP_session_closed() which is called when an existing FTP
session has been terminated.

The call FSRegisterDataClose(data_session_closed) registers the
function data_session_closed() which is called when a data transfer
session is finished.  An FTP client "put" or "get" operation
requires a data session.

The call FSStartServer() starts the FTP server application which
waits for connection requests from FTP clients.


Operation

Use your PC's FTP client application to FTP to the NET+Works board's
IP address.  If your user name isn't listed in validate_user(), the
function returns 1 to notify the FTP Server that the user name isn't
valid.  Otherwise, your user name's "hardcoded" password is passed to
the FTP Server and you are prompted for a password.  If the password
you entered matches the "hardcoded" password, then you are granted
access to the server.

Usser names and passwords are hadcoded in "root.c".

After you are granted access to the server, use the FTP client command
"put filename.ext" to upload a file to the server.  During this
operation, the FTP server repeatedly calls store_data() to transfer
"filename.ext" into the ramImage[] buffer, which is a 2,000,000 byte
buffer.  When the "put" operation completes, the FTP Server calls
data_session_closed() to notify the application that a data session
has been completed.

Afterwards, use the FTP client command "get filename.ext" to
download the file.  The user application keeps track an uploaded
file name (through the "file_name" pointer), so use the same file
name when you download from the server.  During this operation, the
FTP Server repeatedly calls retrieve_data(), which sends out the
file stored in the ramImage[] buffer in packets of 1400 bytes.
When the "get" operation completes, the FTP Server calls
data_session_closed() to notify the application that a data session
has been completed.

Finally, use the FTP client command "quit" to close the connection
with the FTP Server.  When the connection is closed, the FTP Server
calls FTP_session_closed() to notify the application that an FTP
session has been terminated.


One GNU make file is provided.  Build the target 'image' to
generate an image that can be debugged with gdb, and the file 
image.bin which can be written to flash if the bootloader is used.
Build the target 'rom.bin' to create the file rom.bin which 
can be written to ROM if the bootloader is not used.

The following files are provided in this template.

appconf.h         sets application configuration settings
makefile          Make file for the GNU toolset.
readme            this file
root.c            contains applicationStart() function
naftpapp.c        contains the RAM based FTP application code


In addition, the following files in the BSP directory are built
as part of this application.

reset.s         contains the reset code
appconf_api.c   contains code used to read settings in appconf.h



The application uses the following files located in the
netos\src\linkerScripts directory.  These files are generated
when the BSP is built.

bootldr.dat     bootloader configuration file used to generate the
                file image.bin.  It controls the information placed
                in the bootloader header of the image.

image.ldr       GNU linker script used to build an image that can
                be debugged and used with the bootloader.
                
customize.ldr   Customizable GNU linker script
