2011-06-01 21:15:14 +02:00
|
|
|
/****************************************************************************
|
2020-12-13 16:35:40 +01:00
|
|
|
* apps/include/netutils/ftpc.h
|
2011-06-01 21:15:14 +02:00
|
|
|
*
|
2016-07-01 14:36:07 +02:00
|
|
|
* Copyright (C) 2011, 2015-2016 Gregory Nutt. All rights reserved.
|
2012-07-17 05:58:11 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2011-06-01 21:15:14 +02:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-07-01 14:36:07 +02:00
|
|
|
#ifndef __APPS_INCLUDE_NETUTILS_FTPC_H
|
|
|
|
#define __APPS_INCLUDE_NETUTILS_FTPC_H
|
2011-06-01 21:15:14 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2011-06-03 22:27:30 +02:00
|
|
|
#include <sys/types.h>
|
2011-06-01 21:15:14 +02:00
|
|
|
#include <stdbool.h>
|
2011-06-02 01:09:29 +02:00
|
|
|
#include <signal.h>
|
2011-06-01 21:15:14 +02:00
|
|
|
#include <time.h>
|
2011-06-02 01:09:29 +02:00
|
|
|
|
2017-11-07 00:41:30 +01:00
|
|
|
#include <sys/socket.h>
|
2011-06-01 21:15:14 +02:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
2020-12-13 16:35:40 +01:00
|
|
|
|
2011-06-01 21:15:14 +02:00
|
|
|
/* Configuration ************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_FTP_DEFTIMEO
|
|
|
|
# define CONFIG_FTP_DEFTIMEO 30
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_FTP_ANONPWD
|
|
|
|
# define CONFIG_FTP_ANONPWD ""
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_FTP_DEFPORT
|
|
|
|
# define CONFIG_FTP_DEFPORT 21
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_FTP_MAXREPLY
|
2011-06-03 01:45:31 +02:00
|
|
|
# define CONFIG_FTP_MAXREPLY 256
|
2011-06-01 21:15:14 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_FTP_TMPDIR
|
|
|
|
# define CONFIG_FTP_TMPDIR "/tmp"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_FTP_BUFSIZE
|
2011-06-03 01:45:31 +02:00
|
|
|
# define CONFIG_FTP_BUFSIZE 1024
|
2011-06-01 21:15:14 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_FTP_MAXPATH
|
|
|
|
# define CONFIG_FTP_MAXPATH 256
|
|
|
|
#endif
|
|
|
|
|
2011-06-02 01:09:29 +02:00
|
|
|
#ifndef CONFIG_FTP_SIGNAL
|
|
|
|
# define CONFIG_FTP_SIGNAL SIGUSR1
|
|
|
|
#endif
|
|
|
|
|
2011-06-01 21:15:14 +02:00
|
|
|
/* Interface arguments ******************************************************/
|
2020-12-13 16:35:40 +01:00
|
|
|
|
2011-06-01 21:15:14 +02:00
|
|
|
/* These definitions describe how a put operation should be performed */
|
|
|
|
|
|
|
|
#define FTPC_PUT_NORMAL 0 /* Just PUT the file on the server */
|
|
|
|
#define FTPC_PUT_APPEND 1 /* Append file to an existing file on the server */
|
|
|
|
#define FTPC_PUT_UNIQUE 2 /* Create a uniquely named file on the server */
|
|
|
|
#define FTPC_PUT_RESUME 3 /* Resume a previously started PUT transfer */
|
|
|
|
|
|
|
|
/* These definitions describe how a get operation should be performed */
|
|
|
|
|
|
|
|
#define FTPC_GET_NORMAL 0 /* Just GET the file from the server */
|
|
|
|
#define FTPC_GET_APPEND 1 /* Append new file to an existing file */
|
|
|
|
#define FTPC_GET_RESUME 3 /* Resume a previously started GET transfer */
|
|
|
|
|
|
|
|
/* Transfer mode encoding */
|
|
|
|
|
|
|
|
#define FTPC_XFRMODE_UNKNOWN 0 /* Nothing has been transferred yet */
|
|
|
|
#define FTPC_XFRMODE_ASCII 1 /* Last transfer was ASCII mode */
|
|
|
|
#define FTPC_XFRMODE_BINARY 2 /* Last transfer was binary mode */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
2020-12-13 16:35:40 +01:00
|
|
|
|
2011-06-01 21:15:14 +02:00
|
|
|
/* This "handle" describes the FTP session */
|
|
|
|
|
|
|
|
typedef FAR void *SESSION;
|
|
|
|
|
2020-12-13 16:35:40 +01:00
|
|
|
/* This union provides socket address to connect to a host FTP server.
|
2011-06-02 17:05:48 +02:00
|
|
|
*
|
2020-12-13 16:35:40 +01:00
|
|
|
* in4, in6 - The IPv4 or IPv6 address of the FTP server (or the proxy)
|
|
|
|
* for the FTP server.
|
2011-06-02 17:05:48 +02:00
|
|
|
*/
|
2011-06-01 21:15:14 +02:00
|
|
|
|
2017-11-07 00:41:30 +01:00
|
|
|
union ftpc_sockaddr_u
|
2011-06-01 21:15:14 +02:00
|
|
|
{
|
2017-11-07 00:41:30 +01:00
|
|
|
uint8_t raw[sizeof(struct sockaddr_storage)];
|
|
|
|
struct sockaddr_storage ss;
|
|
|
|
struct sockaddr sa;
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
struct sockaddr_in6 in6;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
struct sockaddr_in in4;
|
|
|
|
#endif
|
2011-06-01 21:15:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* This structure provides FTP login information */
|
|
|
|
|
|
|
|
struct ftpc_login_s
|
|
|
|
{
|
|
|
|
FAR const char *uname; /* Login uname */
|
|
|
|
FAR const char *pwd; /* Login pwd */
|
|
|
|
FAR const char *rdir; /* Initial remote directory */
|
|
|
|
bool pasv; /* true: passive connection mode */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This structure describes one simple directory listing. The directory
|
|
|
|
* list container as well the individual filename strings are allocated.
|
2020-02-23 05:51:44 +01:00
|
|
|
* The number of names in the actual allocated array is variable, given
|
2011-06-01 21:15:14 +02:00
|
|
|
* by the nnames field.
|
|
|
|
*
|
|
|
|
* Since the structure and file names are allocated, they must be freed
|
|
|
|
* by calling ftpc_dirfree() when they are no longer needed. Allocated
|
2015-06-13 02:07:47 +02:00
|
|
|
* name strings may be "stolen" from the array but the pointer int the
|
2011-06-01 21:15:14 +02:00
|
|
|
* array should be nullified so that the string is not freed by
|
|
|
|
* ftpc_dirfree().
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ftpc_dirlist_s
|
|
|
|
{
|
|
|
|
unsigned int nnames; /* Number of entries in name[] array */
|
|
|
|
FAR char *name[1]; /* Filename with absolute path */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SIZEOF_FTPC_DIRLIST(n) \
|
|
|
|
(sizeof(struct ftpc_dirlist_s) + ((n)-1)*sizeof(FAR char *))
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#define EXTERN extern "C"
|
2015-06-13 02:07:47 +02:00
|
|
|
extern "C"
|
|
|
|
{
|
2011-06-01 21:15:14 +02:00
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-12-13 16:35:40 +01:00
|
|
|
* Public Function Prototypes
|
2011-06-01 21:15:14 +02:00
|
|
|
****************************************************************************/
|
2020-12-13 16:35:40 +01:00
|
|
|
|
2011-06-01 21:15:14 +02:00
|
|
|
/* Connection management ****************************************************/
|
|
|
|
|
2017-11-07 00:41:30 +01:00
|
|
|
SESSION ftpc_connect(FAR union ftpc_sockaddr_u *server);
|
2015-06-13 02:07:47 +02:00
|
|
|
void ftpc_disconnect(SESSION handle);
|
2011-06-01 21:15:14 +02:00
|
|
|
|
|
|
|
/* FTP commands *************************************************************/
|
|
|
|
|
2015-06-13 02:07:47 +02:00
|
|
|
int ftpc_login(SESSION handle, FAR struct ftpc_login_s *login);
|
|
|
|
int ftpc_quit(SESSION handle);
|
2011-06-01 21:15:14 +02:00
|
|
|
|
2015-06-13 02:07:47 +02:00
|
|
|
int ftpc_chdir(SESSION handle, FAR const char *path);
|
|
|
|
FAR char *ftpc_rpwd(SESSION handle);
|
|
|
|
int ftpc_cdup(SESSION handle);
|
|
|
|
int ftpc_mkdir(SESSION handle, FAR const char *path);
|
|
|
|
int ftpc_rmdir(SESSION handle, FAR const char *path);
|
2011-06-01 21:15:14 +02:00
|
|
|
|
2015-06-13 02:07:47 +02:00
|
|
|
int ftpc_unlink(SESSION handle, FAR const char *path);
|
|
|
|
int ftpc_chmod(SESSION handle, FAR const char *path, FAR const char *mode);
|
2020-12-13 16:35:40 +01:00
|
|
|
int ftpc_rename(SESSION handle, FAR const char *oldname,
|
|
|
|
FAR const char *newname);
|
2015-06-13 02:07:47 +02:00
|
|
|
off_t ftpc_filesize(SESSION handle, FAR const char *path);
|
|
|
|
time_t ftpc_filetime(SESSION handle, FAR const char *filename);
|
2011-06-01 21:15:14 +02:00
|
|
|
|
2015-06-13 02:07:47 +02:00
|
|
|
int ftpc_idle(SESSION handle, unsigned int idletime);
|
|
|
|
int ftpc_noop(SESSION handle);
|
|
|
|
int ftpc_help(SESSION handle, FAR const char *arg);
|
2011-06-01 21:15:14 +02:00
|
|
|
|
2011-06-02 01:09:29 +02:00
|
|
|
/* Directory listings *******************************************************/
|
2011-06-01 21:15:14 +02:00
|
|
|
|
2015-06-13 02:07:47 +02:00
|
|
|
FAR struct ftpc_dirlist_s *ftpc_listdir(SESSION handle,
|
|
|
|
FAR const char *dirpath);
|
|
|
|
void ftpc_dirfree(FAR struct ftpc_dirlist_s *dirlist);
|
2011-06-01 21:15:14 +02:00
|
|
|
|
|
|
|
/* File transfers ***********************************************************/
|
|
|
|
|
2015-06-13 02:07:47 +02:00
|
|
|
int ftpc_getfile(SESSION handle, FAR const char *rname,
|
|
|
|
FAR const char *lname, uint8_t how, uint8_t xfrmode);
|
|
|
|
int ftp_putfile(SESSION handle, FAR const char *lname,
|
|
|
|
FAR const char *rname, uint8_t how, uint8_t xfrmode);
|
2011-06-01 21:15:14 +02:00
|
|
|
|
|
|
|
/* FTP response *************************************************************/
|
|
|
|
|
2015-06-13 02:07:47 +02:00
|
|
|
FAR char *ftpc_response(SESSION handle);
|
2011-06-01 21:15:14 +02:00
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2012-07-17 05:58:11 +02:00
|
|
|
|
2016-07-01 14:36:07 +02:00
|
|
|
#endif /* __APPS_INCLUDE_NETUTILS_FTPC_H */
|