File transfer protocol. More...
Data Structures | |
struct | FTPSESSION |
FTP session information structure. More... | |
Functions | |
int | NutFtpRespondOk (FTPSESSION *session, int code) |
Send a positive response. | |
int | NutFtpRespondBad (FTPSESSION *session, int code) |
Send a negative response. | |
int | NutFtpSendMode (FTPSESSION *session, int binary) |
Send a response including the specified transfer mode. | |
char * | CreateFullPathName (char *root, char *work, char *path) |
Create an absolute path name. | |
TCPSOCKET * | NutFtpDataConnect (FTPSESSION *session) |
Establish an FTP connection for data transfer. | |
int | NutRegisterFtpRoot (const char *path) |
Register the FTP server's root directory. | |
int | NutRegisterFtpUser (const char *user, const char *pass) |
Register an FTP user. | |
FTPSESSION * | NutFtpOpenSession (TCPSOCKET *sock) |
Open an FTP server session. | |
void | NutFtpCloseSession (FTPSESSION *session) |
Close an FTP server session. | |
int | NutFtpProcessCwd (FTPSESSION *session, char *path) |
Process an FTP client's CWD command. | |
int | NutFtpProcessDelete (FTPSESSION *session, char *path) |
Process an FTP client's DELE command. | |
int | NutFtpTransferFile (FTPSESSION *session, char *path, int mode) |
Transfer a file to or from the FTP client. | |
int | NutFtpTransferDirectoryOptions (FTPSESSION *session, char *path, int options) |
Process an FTP client's LIST or NLST command. | |
int | NutFtpTransferDirectory (FTPSESSION *session, char *path) |
Process an FTP client's LIST or NLST command. | |
int | NutFtpProcessMkd (FTPSESSION *session, char *path) |
Process an FTP client's MKD command. | |
int | NutFtpRenamePrepare (FTPSESSION *session, char *path) |
int | NutFtpRenameAction (FTPSESSION *session, char *path) |
int | NutFtpProcessPass (FTPSESSION *session, char *pass) |
Process an FTP client's PASS command. | |
int | NutFtpProcessPassiv (FTPSESSION *session) |
Process an FTP client's PASV command. | |
int | NutFtpProcessPort (FTPSESSION *session, char *args) |
Process an FTP client's PORT command. | |
int | NutFtpProcessPwd (FTPSESSION *session) |
Process an FTP client's PWD command. | |
int | NutFtpProcessRmd (FTPSESSION *session, char *path) |
Process an FTP client's RMD command. | |
int | NutFtpProcessSystem (FTPSESSION *session) |
Process an FTP client's SYST command. | |
int | NutFtpProcessType (FTPSESSION *session, char *typecode) |
Process an FTP client's TYPE command. | |
int | NutFtpProcessUser (FTPSESSION *session, char *user) |
Process an FTP client's USER command. | |
int | NutFtpProcessRequest (FTPSESSION *session, char *request) |
Process an FTP request. | |
int | NutFtpServerSession (TCPSOCKET *sock) |
Process an FTP sever session. | |
FTP Server Configuration | |
The Nut/OS Configurator may be used to override the default values. | |
#define | FTP_MAX_CMDBUF 128 |
UDP port of DHCP server. | |
FTP Server Configuration | |
The Nut/OS Configurator may be used to override the default values. | |
#define | FTP_ROOTPATH "PNUT:" |
Default FTP root path. | |
#define | FTP_DATA_PORT 20 |
Default data port. |
File transfer protocol.
Note, that FTP servers don't make much sense without a file system providing write access. Right now, FTP had been tested with the PNUT file system only.
Internet File Transfer Protocol Server.
#define FTP_MAX_CMDBUF 128 |
UDP port of DHCP server.
Referenced by NutFtpServerSession().
#define FTP_ROOTPATH "PNUT:" |
Default FTP root path.
Referenced by NutRegisterFtpRoot().
#define FTP_DATA_PORT 20 |
Default data port.
Referenced by NutFtpOpenSession().
int NutFtpRespondOk | ( | FTPSESSION * | session, |
int | code | ||
) |
Send a positive response.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
code | Response code. |
References fflush(), fprintf_P, FTPSESSION::ftp_stream, printf, and prog_char.
Referenced by NutFtpProcessCwd(), NutFtpProcessDelete(), NutFtpProcessMkd(), NutFtpProcessPass(), NutFtpProcessPort(), NutFtpProcessRequest(), NutFtpProcessRmd(), NutFtpProcessType(), NutFtpProcessUser(), NutFtpRenameAction(), NutFtpRenamePrepare(), NutFtpTransferDirectoryOptions(), and NutFtpTransferFile().
int NutFtpRespondBad | ( | FTPSESSION * | session, |
int | code | ||
) |
Send a negative response.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
code | Response code. |
References fflush(), fprintf_P, FTPSESSION::ftp_stream, printf, and prog_char.
Referenced by NutFtpProcessCwd(), NutFtpProcessDelete(), NutFtpProcessMkd(), NutFtpProcessPass(), NutFtpProcessPort(), NutFtpProcessRequest(), NutFtpProcessRmd(), NutFtpProcessUser(), NutFtpRenameAction(), NutFtpRenamePrepare(), NutFtpServerSession(), NutFtpTransferDirectoryOptions(), and NutFtpTransferFile().
int NutFtpSendMode | ( | FTPSESSION * | session, |
int | binary | ||
) |
Send a response including the specified transfer mode.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
binary | 0 indicates ASCII transfer mode. |
References fflush(), fputs_P, FTPSESSION::ftp_stream, printf, and prog_char.
Referenced by NutFtpTransferDirectoryOptions(), and NutFtpTransferFile().
char* CreateFullPathName | ( | char * | root, |
char * | work, | ||
char * | path | ||
) |
Create an absolute path name.
Combines an absolute directory path with a relative path name to a full absolute path name. The absolute directory is split into two parts, the root and the current work directory. The resulting path will never be above the specified root.
root | Non-empty absolute root directory path including the device name, but without a trailing slash. |
work | Absolute work directory path below root including a leading, but without a trailing slash. This path is ignored if the relative path starts with a slash. |
path | Relative path name of a file or directory without any trailing slash. |
References malloc(), NULL, strcpy(), and strlen().
Referenced by NutFtpProcessRequest().
TCPSOCKET* NutFtpDataConnect | ( | FTPSESSION * | session | ) |
Establish an FTP connection for data transfer.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
References FTPSESSION::ftp_data_ip, FTPSESSION::ftp_data_port, FTPSESSION::ftp_maxseg, FTPSESSION::ftp_passive, NutTcpAccept(), NutTcpCloseSocket(), NutTcpConnect(), NutTcpCreateSocket(), NutTcpError(), NutTcpSetSockOpt(), printf_P(), prog_char, puts_P(), rc, and TCP_MAXSEG.
Referenced by NutFtpTransferDirectoryOptions(), and NutFtpTransferFile().
int NutRegisterFtpRoot | ( | const char * | path | ) |
Register the FTP server's root directory.
Only one root directory is supported. Subsequent calls will override previous settings.
path | Path name of the root directory. Must include the device name followed by a colon followed by an absolute directory path. May be set to NULL for the default FTP_ROOTPATH. |
References free(), FTP_ROOTPATH, malloc(), NULL, strchr(), strcpy(), and strlen().
Referenced by main(), and NutFtpServerSession().
int NutRegisterFtpUser | ( | const char * | user, |
const char * | pass | ||
) |
Register an FTP user.
Only one username/password pair is supported. Subsequent calls will override previous settings.
user | User's name. |
pass | Uncrypted password for the specified user. |
References free(), NULL, and strdup().
FTPSESSION* NutFtpOpenSession | ( | TCPSOCKET * | sock | ) |
Open an FTP server session.
sock | Socket of an established TCP connection. |
References _fdopen(), free(), FTPSESSION::ftp_cwd, FTPSESSION::ftp_data_port, FTP_DATA_PORT, FTPSESSION::ftp_maxseg, FTPSESSION::ftp_sock, FTPSESSION::ftp_stream, malloc(), memset(), and tcp_socket::so_mss.
Referenced by NutFtpServerSession().
void NutFtpCloseSession | ( | FTPSESSION * | session | ) |
Close an FTP server session.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
References fclose(), free(), FTPSESSION::ftp_cwd, FTPSESSION::ftp_renamesource, and FTPSESSION::ftp_stream.
Referenced by NutFtpServerSession().
int NutFtpProcessCwd | ( | FTPSESSION * | session, |
char * | path | ||
) |
Process an FTP client's CWD command.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
path | Full absolute path name of the directory. |
References free(), FTPSESSION::ftp_cwd, NULL, NutFtpRespondBad(), NutFtpRespondOk(), S_ISDIR, stat::st_mode, stat(), strcmp(), strdup(), and strlen().
Referenced by NutFtpProcessRequest().
int NutFtpProcessDelete | ( | FTPSESSION * | session, |
char * | path | ||
) |
Process an FTP client's DELE command.
Causes the specified file to be deleted.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
path | Full absolute path name of the file. |
References NutFtpRespondBad(), NutFtpRespondOk(), and unlink().
Referenced by NutFtpProcessRequest().
int NutFtpTransferFile | ( | FTPSESSION * | session, |
char * | path, | ||
int | mode | ||
) |
Transfer a file to or from the FTP client.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
path | Full absolute path name of the file. |
mode | If set to zero, the server will accept the data transferred via the data connection and to store the data as a file. If the file exists, then its contents will be replaced by the data being transferred. A new file is created, if the file does not already exist. If this parameter is not equal zero, then the server will transfer a copy of the specified file. |
References _close(), _O_BINARY, _O_CREAT, _O_RDONLY, _O_TRUNC, _open(), _read(), _write(), free(), FTPSESSION::ftp_tran_mode, malloc(), NutFtpDataConnect(), NutFtpRespondBad(), NutFtpRespondOk(), NutFtpSendMode(), NutSleep(), NutTcpCloseSocket(), NutTcpReceive(), NutTcpSend(), printf, prog_char, puts_P(), S_ISREG, tcp_socket::so_mss, stat::st_mode, stat(), and unlink().
Referenced by NutFtpProcessRequest().
int NutFtpTransferDirectoryOptions | ( | FTPSESSION * | session, |
char * | path, | ||
int | options | ||
) |
Process an FTP client's LIST or NLST command.
Causes a directory listing to be sent to the client.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
path | Full absolute path name of the directory. |
options | Set to 1 to incude filenames beginning with a "." (unix hidden files) |
References _fdopen(), closedir(), dirent::d_name, fclose(), fprintf_P, fputc(), fputs(), free(), gmtime(), malloc(), NutFtpDataConnect(), NutFtpRespondBad(), NutFtpRespondOk(), NutFtpSendMode(), NutTcpCloseSocket(), opendir(), prog_char, readdir(), S_ISDIR, stat::st_mode, stat::st_mtime, stat::st_size, stat(), strcat(), strcpy(), strlen(), _tm::tm_hour, _tm::tm_mday, _tm::tm_min, and _tm::tm_mon.
Referenced by NutFtpProcessRequest(), and NutFtpTransferDirectory().
int NutFtpTransferDirectory | ( | FTPSESSION * | session, |
char * | path | ||
) |
Process an FTP client's LIST or NLST command.
Causes a directory listing to be sent to the client.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
path | Full absolute path name of the directory. |
References NutFtpTransferDirectoryOptions().
int NutFtpProcessMkd | ( | FTPSESSION * | session, |
char * | path | ||
) |
Process an FTP client's MKD command.
Causes the specified directory to be created.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
path | Full absolute path name of the directory. |
References mkdir(), NutFtpRespondBad(), and NutFtpRespondOk().
Referenced by NutFtpProcessRequest().
int NutFtpRenamePrepare | ( | FTPSESSION * | session, |
char * | path | ||
) |
References free(), FTPSESSION::ftp_renamesource, NULL, NutFtpRespondBad(), NutFtpRespondOk(), stat(), and strdup().
Referenced by NutFtpProcessRequest().
int NutFtpRenameAction | ( | FTPSESSION * | session, |
char * | path | ||
) |
References free(), FTPSESSION::ftp_renamesource, NULL, NutFtpRespondBad(), NutFtpRespondOk(), and rename().
Referenced by NutFtpProcessRequest().
int NutFtpProcessPass | ( | FTPSESSION * | session, |
char * | pass | ||
) |
Process an FTP client's PASS command.
Only one login per session is accepted.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
pass | Password. |
References FTPSESSION::ftp_login, NutFtpRespondBad(), NutFtpRespondOk(), and strcmp().
Referenced by NutFtpProcessRequest().
int NutFtpProcessPassiv | ( | FTPSESSION * | session | ) |
Process an FTP client's PASV command.
This command requests the server to listen on a data port and to wait for a connection rather than initiate one upon receipt of a transfer command.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
References fflush(), fprintf_P, FTPSESSION::ftp_passive, FTPSESSION::ftp_sock, FTPSESSION::ftp_stream, prog_char, and tcp_socket::so_local_addr.
Referenced by NutFtpProcessRequest().
int NutFtpProcessPort | ( | FTPSESSION * | session, |
char * | args | ||
) |
Process an FTP client's PORT command.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
args | Command argument, which is the concatenation of the 32-bit internet host address and a 16-bit TCP port address. This address information is broken into 8-bit fields and the value of each field is transmitted as a decimal number. |
References FTPSESSION::ftp_data_ip, FTPSESSION::ftp_data_port, FTPSESSION::ftp_sock, NutFtpRespondBad(), NutFtpRespondOk(), and tcp_socket::so_remote_addr.
Referenced by NutFtpProcessRequest().
int NutFtpProcessPwd | ( | FTPSESSION * | session | ) |
Process an FTP client's PWD command.
Causes the name of the current working directory to be returned in the reply.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
References fprintf_P, FTPSESSION::ftp_cwd, FTPSESSION::ftp_stream, printf, and prog_char.
Referenced by NutFtpProcessRequest().
int NutFtpProcessRmd | ( | FTPSESSION * | session, |
char * | path | ||
) |
Process an FTP client's RMD command.
Causes the specified directory to be removed.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
path | Full absolute path name of the directory. |
References NutFtpRespondBad(), NutFtpRespondOk(), and rmdir().
Referenced by NutFtpProcessRequest().
int NutFtpProcessSystem | ( | FTPSESSION * | session | ) |
Process an FTP client's SYST command.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
References fputs_P, FTPSESSION::ftp_stream, printf, and prog_char.
Referenced by NutFtpProcessRequest().
int NutFtpProcessType | ( | FTPSESSION * | session, |
char * | typecode | ||
) |
Process an FTP client's TYPE command.
The type is not fully checked. Any argument starting with the letters 'A' or 'a' will switch the transfer mode to ASCII. Otherwise binary mode is set.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
typecode | Command arguments. |
References FTPSESSION::ftp_tran_mode, and NutFtpRespondOk().
Referenced by NutFtpProcessRequest().
int NutFtpProcessUser | ( | FTPSESSION * | session, |
char * | user | ||
) |
Process an FTP client's USER command.
Only one login per session is accepted.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
user | User name. |
References FTPSESSION::ftp_login, NutFtpRespondBad(), NutFtpRespondOk(), and strcmp().
Referenced by NutFtpProcessRequest().
int NutFtpProcessRequest | ( | FTPSESSION * | session, |
char * | request | ||
) |
Process an FTP request.
This routine implements the protocol interpreter of the FTP server.
session | Pointer to an FTPSESSION structure, obtained by a previous call to NutFtpOpenSession(). |
request | Request string. |
References CreateFullPathName(), free(), FTPSESSION::ftp_cwd, FTPSESSION::ftp_login, FTPSESSION::ftp_renamesource, NULL, NutFtpProcessCwd(), NutFtpProcessDelete(), NutFtpProcessMkd(), NutFtpProcessPass(), NutFtpProcessPassiv(), NutFtpProcessPort(), NutFtpProcessPwd(), NutFtpProcessRmd(), NutFtpProcessSystem(), NutFtpProcessType(), NutFtpProcessUser(), NutFtpRenameAction(), NutFtpRenamePrepare(), NutFtpRespondBad(), NutFtpRespondOk(), NutFtpTransferDirectoryOptions(), NutFtpTransferFile(), printf, rc, strchr(), strcmp_P, and strlen().
Referenced by NutFtpServerSession().
int NutFtpServerSession | ( | TCPSOCKET * | sock | ) |
Process an FTP sever session.
Processes FTP requests on an established connection with an FTP client. This routine completely implements an FTP server except TCP connect and disconnect.
For file transfers, the same maximum segment size and timeouts as set for this socket will be used for the data connection.
sock | Socket of an established TCP connection. |
References fflush(), fgets(), fprintf_P, free(), FTP_MAX_CMDBUF, FTPSESSION::ftp_stream, localtime(), malloc(), NutFtpCloseSession(), NutFtpOpenSession(), NutFtpProcessRequest(), NutFtpRespondBad(), NutRegisterFtpRoot(), NutVersionString(), printf, printf_P(), rc, strlen(), time(), _tm::tm_hour, _tm::tm_mday, _tm::tm_min, _tm::tm_mon, and _tm::tm_sec.