4G_module/include/cmiot/cm_ftp.h

280 lines
7.7 KiB
C
Raw Permalink Normal View History

2024-09-02 17:54:29 +08:00
/**
* @file cm_ftp.h
* @brief FTP接口
* @copyright Copyright © 2022 China Mobile IOT. All rights reserved.
* @author By mxc
* @date 2022/06/07
*
* @defgroup FTP
* @ingroup FTP
* @{
*/
#ifndef __CM_FTP_H__
#define __CM_FTP_H__
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
#include "sockets.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/**FTP配置*/
typedef struct
{
uint8_t *url; /*!< FTP服务器URL或IP*/
int32_t port; /*!< FTP服务器端口*/
uint8_t *username; /*!< FTP服务器用户名*/
uint8_t *passwd; /*!< FTP服务器密码*/
int32_t trans_mode; /*!< FTP传输模式0主动模式1被动模式。该参数不生效目前仅支持被动模式*/
int32_t data_type; /*!< FTP数据传输类型0Binary1ASCII*/
int32_t rsptimeout; /*!< FTP响应超时时间单位ms建议设置为1s以上*/
int32_t ssl_mode; /*!< FTP SSL模式0无SSL目前不支持SSL*/
int32_t ssl_id; /*!< FTP SSL通道ID取值范围参考SSL模块目前不支持SSL*/
int32_t cid; /*!< FTP PDP通道ID*/
} cm_ftp_config_t;
/**FTP文件信息*/
typedef struct
{
uint32_t file_attr; /*!< 0相对路径 1文件 */
uint32_t file_size; /*!< file_attr = 1时为文件大小否则该参数无效 */
uint8_t file_name[256]; /*!< file_attr = 1时为文件名称 file_attr = 0时为相对路径名称 */
uint8_t file_permision; /*!< 第0位代表是否可执行第1位代表是否可写第2位代表是否可读。0是 1否*/
uint32_t file_modify_time; /*!< 修改时间unix时间戳*/
} cm_ftp_file_data_t;
/**FTP状态*/
typedef enum
{
FTP_STATE_DISCONNECTED = 0, /*!< FTP连接断开 */
FTP_STATE_CONNECTED, /*!< FTP连接建立 */
FTP_STATE_GETTING, /*!< FTP正在下载文件*/
FTP_STATE_PUTTING /*!< FTP正在上传文件*/
} cm_ftp_state_e;
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C" {
#else
#define EXTERN extern
#endif
/****************************************************************************/
/**
* @brief FTP连接
*
* @param [in] config FTP配置
*
* @return
* >= 0 - FTP连接句柄 \n
* < 0 -
*/
int32_t cm_ftp_open(cm_ftp_config_t *config);
/**
* @brief FTP连接
*
* @param [in] handle FTP连接句柄
*
* @return
* = 0 - \n
* < 0 -
*/
int32_t cm_ftp_close(int32_t handle);
/**
* @brief
*
* @param [in] handle FTP连接句柄
* @param [in] dir
*
* @return
* = 0 - \n
* < 0 -
*/
int32_t cm_ftp_create_dir(int32_t handle, const char *dir);
/**
* @brief
*
* @param [in] handle FTP连接句柄
* @param [in] dir
*
* @return
* = 0 - \n
* < 0 -
*/
int32_t cm_ftp_remove_dir(int32_t handle, const char *dir);
/**
* @brief
*
* @param [in] handle FTP连接句柄
* @param [in] file
*
* @return
* = 0 - \n
* < 0 -
*/
int32_t cm_ftp_delete_file(int32_t handle, const char *file);
/**
* @brief
*
* @param [in] handle FTP连接句柄
* @param [in] dir
*
* @return
* = 0 - \n
* < 0 -
*/
int32_t cm_ftp_set_current_dir(int32_t handle, const char *dir);
/**
* @brief
*
* @param [in] handle FTP连接句柄
* @param [out] dir
*
* @return
* = 0 - \n
* < 0 -
*/
int32_t cm_ftp_get_current_dir(int32_t handle, char *dir);
/**
* @brief
*
* @param [in] handle FTP连接句柄
* @param [in] old_file
* @param [in] new_file
*
* @return
* = 0 - \n
* < 0 -
*/
int32_t cm_ftp_rename_file(int32_t handle, const char *old_file, const char *new_file);
/**
* @brief
*
* @param [in] handle FTP连接句柄
* @param [in] file
*
* @return
* >= 0 - \n
* < 0 -
*/
int32_t cm_ftp_get_file_size(int32_t handle, const char *file);
/**
* @brief FTP打开查找
*
* @param [in] handle FTP连接句柄
* @param [in] path
* @param [out] file_data
*
* @return
* >= 0 - FTP查找句柄 \n
* < 0 -
*/
int32_t cm_ftp_find_first(int32_t handle, const char *path, cm_ftp_file_data_t *file_data);
/**
* @brief FTP获取文件夹下文件信息
*
* @param [in] handle FTP连接句柄
* @param [in] find_fd cm_ftp_find_first接口返回值
* @param [out] file_data
*
* @return
* >= 0 - \n
* < 0 -
*/
int32_t cm_ftp_find_next(int32_t handle, int32_t find_fd, cm_ftp_file_data_t *file_data);
/**
* @brief
*
* @param [in] handle FTP连接句柄
* @param [in] find_fd cm_ftp_find_first接口返回值
*
* @return
* = 0 - \n
* < 0 -
*/
int32_t cm_ftp_find_close(int32_t handle, int32_t find_fd);
/**
* @brief FTP从服务器获取文件
*
* @param [in] handle FTP连接句柄
* @param [in] data_type FTP数据传输类型0Binary1ASCII
* @param [in] file
* @param [in] offset
* @param [out] data
* @param [in] len
*
* @return
* >= 0 - \n
* < 0 -
*
* @details data_type未生效cm_ftp_open传入的配置参数
*/
int32_t cm_ftp_get_file(int32_t handle, int32_t data_type, const char *file, int32_t offset, uint8_t *data, uint32_t len);
/**
* @brief FTP向服务器推送文件
*
* @param [in] handle FTP连接句柄
* @param [in] mode 0: 1
* @param [in] file
* @param [in] data
* @param [in] len
*
* @return
* = 0 - \n
* < 0 -
*/
int32_t cm_ftp_put_file(int32_t handle, int32_t mode, char *file, uint8_t *data, uint32_t len);
/**
* @brief FTP连接状态
*
* @param [in] handle FTP连接句柄
*
* @return
* FTP连接状态cm_ftp_state_e
*/
cm_ftp_state_e cm_ftp_get_state(int32_t handle);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __CM_FTP_CLIENT_H__ */
/** @}*/