ftpclient
This commit is contained in:
parent
3aea5d919e
commit
44a5cb0d24
|
@ -134,7 +134,7 @@ ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
|
|||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_FTPCLIENT),y)
|
||||
SRC_FILES +=
|
||||
SRC_FILES += test_ftpclient/test_ftpclient.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_LORA_P2P),y)
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
# 基于矽璓已实现的Lwip,在ARM上实现FTP协议的Client功能##
|
||||
|
||||
## 1. 简介
|
||||
基于矽璓已实现的Lwip,在ARM上实现FTP协议的Client功能,实现文件的上传与下载。
|
||||
即基于XiZi内核移植支持FTP Client库,个人电脑中安装FTP服务端软件,充当FTP Server角色,在其上上传10个4KB文件,执行FTP协议的Client实现下载FTP Server上的10个文件。
|
||||
|
||||
## 2. 数据结构设计说明
|
||||
定义zFTP通信管理数据结构
|
||||
```
|
||||
typedef struct zftp_client_struct {
|
||||
char user_name[ZFTP_USER_NAME_LEN];
|
||||
char password[ZFTP_PASSWORD_LEN];
|
||||
char server_ip[ZFTP_SERVER_IP_LEN];
|
||||
char data_port[6];
|
||||
char control_port[6];
|
||||
int control_socket; /* FTP控制socket */
|
||||
int data_socket; /* FTP数据socket */
|
||||
down_callback download_write;
|
||||
up_callback upload_read;
|
||||
void* user_data;
|
||||
int errorno;
|
||||
|
||||
}zftp_client;
|
||||
```
|
||||
---------
|
||||
ftp登录函数
|
||||
```
|
||||
zftp_client* zFTP_login(char* user_name, char* password, char* server_ip);
|
||||
```
|
||||
---------
|
||||
文件上传与回显
|
||||
```
|
||||
int zFTP_set_callback(zftp_client* ftp, down_callback dw_write, up_callback up_read, void* user_data);
|
||||
```
|
||||
---------
|
||||
得到文件大小
|
||||
```
|
||||
int zFTP_get_filesize(zftp_client* ftp, char* file_name, rt_uint32_t* file_size);
|
||||
```
|
||||
---------
|
||||
改变ftp服务器路径
|
||||
```
|
||||
int zFTP_change_path(zftp_client* ftp, char* path);
|
||||
```
|
||||
---------
|
||||
从服务器下载文件
|
||||
```
|
||||
int zFTP_download_file(zftp_client* ftp, char* file_name);
|
||||
```
|
||||
---------
|
||||
上传文件到ftp服务器
|
||||
```
|
||||
int zFTP_upload_file(zftp_client* ftp, char* file_name);
|
||||
```
|
||||
---------
|
||||
退出登录并且停止服务器
|
||||
```
|
||||
int zFTP_quit(zftp_client* ftp);
|
||||
```
|
||||
---------
|
||||
## 3. 测试程序说明
|
||||
测试了文件的上传与下载,FTP的TCP链接未建立成功
|
||||
|
||||
## 4. 运行结果(##需结合运行测试截图按步骤说明##)
|
||||
编译,烧录bin文件
|
||||

|
||||
查看shell命令
|
||||

|
||||
测试结果
|
||||

|
||||
|
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
Binary file not shown.
After Width: | Height: | Size: 143 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,128 @@
|
|||
/**
|
||||
* @file test_ftpclient.h
|
||||
* @author Zhao shimin
|
||||
* @brief ftp
|
||||
* @version 0.1
|
||||
* @date 2023-10-05
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
* from https://github.com/longtengmcu/zFTP/blob/master/inc/zFTP.h
|
||||
*/
|
||||
|
||||
|
||||
/*********************************************************************************************************
|
||||
* 定义FTP的客户端的存储的缓冲区长<EFBFBD>?
|
||||
*********************************************************************************************************/
|
||||
#ifndef ZFTP_USER_NAME_LEN
|
||||
#define ZFTP_USER_NAME_LEN 20
|
||||
#endif
|
||||
|
||||
#ifndef ZFTP_PASSWORD_LEN
|
||||
#define ZFTP_PASSWORD_LEN 20
|
||||
#endif
|
||||
|
||||
#ifndef ZFTP_SERVER_IP_LEN
|
||||
#define ZFTP_SERVER_IP_LEN 20
|
||||
#endif
|
||||
|
||||
#ifndef ZFTP_FILE_DATA_BUF_SIZE
|
||||
#define ZFTP_FILE_DATA_BUF_SIZE 4096 //单位字节
|
||||
#endif
|
||||
|
||||
|
||||
#define ZFTP_SERVER_CONTROL_PORT "21"
|
||||
#define ZFTP_SERVER_DATA_PORT "22"
|
||||
|
||||
/*FTP communicate command timeout, unit:ms */
|
||||
#define ZFTP_CMD_TIMEOUT 2000
|
||||
|
||||
typedef int32_t rt_uint32_t;
|
||||
typedef int16_t rt_uint16_t;
|
||||
typedef int8_t rt_uint8_t;
|
||||
typedef int (*down_callback)(void* handle, char* file_name, rt_uint8_t* buf, rt_uint32_t len, rt_uint32_t file_pos, rt_uint32_t total_len);
|
||||
typedef int (*up_callback)(void* handle, char* file_name, rt_uint8_t* buf, rt_uint32_t len, rt_uint32_t file_pos, rt_uint32_t* read_len, rt_uint32_t* total_len);
|
||||
|
||||
/*********************************************************************************************************
|
||||
* 定义zFTP通信管理数据结构
|
||||
*********************************************************************************************************/
|
||||
typedef struct zftp_client_struct {
|
||||
char user_name[ZFTP_USER_NAME_LEN];
|
||||
char password[ZFTP_PASSWORD_LEN];
|
||||
char server_ip[ZFTP_SERVER_IP_LEN];
|
||||
char data_port[6];
|
||||
char control_port[6];
|
||||
int control_socket; /* FTP控制socket */
|
||||
int data_socket; /* FTP数据socket */
|
||||
down_callback download_write;
|
||||
up_callback upload_read;
|
||||
void* user_data;
|
||||
int errorno;
|
||||
|
||||
}zftp_client;
|
||||
|
||||
/*********************************************************************************************************
|
||||
** Function name<EFBFBD>? zFTP_login()
|
||||
** Descriptions: ftp login server
|
||||
** input parameters<EFBFBD>? user_name, password, server_ip
|
||||
** output parameters<EFBFBD>? None
|
||||
** Returned value: zftp_client
|
||||
*********************************************************************************************************/
|
||||
zftp_client* zFTP_login(char* user_name, char* password, char* server_ip);
|
||||
|
||||
/*********************************************************************************************************
|
||||
** Function name<EFBFBD>? zFTP_set_callback()
|
||||
** Descriptions: set the file download and upload callback function
|
||||
** input parameters<EFBFBD>? ftp, dw_write, up_read, user_data
|
||||
** output parameters<EFBFBD>? None
|
||||
** Returned value: RT_EOK
|
||||
*********************************************************************************************************/
|
||||
int zFTP_set_callback(zftp_client* ftp, down_callback dw_write, up_callback up_read, void* user_data);
|
||||
|
||||
/*********************************************************************************************************
|
||||
** Function name<EFBFBD>? zFTP_get_filesize()
|
||||
** Descriptions: get the file size from FTP server
|
||||
** input parameters<EFBFBD>? ftp, path, file_name
|
||||
** output parameters<EFBFBD>? file_size
|
||||
** Returned value: zftp_client
|
||||
*********************************************************************************************************/
|
||||
int zFTP_get_filesize(zftp_client* ftp, char* file_name, rt_uint32_t* file_size);
|
||||
|
||||
/*********************************************************************************************************
|
||||
** Function name<EFBFBD>? zFTP_change_path()
|
||||
** Descriptions: change the path of FTP server
|
||||
** input parameters<EFBFBD>? ftp, path, path
|
||||
** output parameters<EFBFBD>? file_size
|
||||
** Returned value: zftp_client
|
||||
*********************************************************************************************************/
|
||||
int zFTP_change_path(zftp_client* ftp, char* path);
|
||||
|
||||
/*********************************************************************************************************
|
||||
** Function name<EFBFBD>? zFTP_download_file()
|
||||
** Descriptions: download the file from FTP server
|
||||
** input parameters<EFBFBD>? ftp, path, file_name
|
||||
** output parameters<EFBFBD>? file_size
|
||||
** Returned value: zftp_client
|
||||
*********************************************************************************************************/
|
||||
int zFTP_download_file(zftp_client* ftp, char* file_name);
|
||||
|
||||
/*********************************************************************************************************
|
||||
** Function name<EFBFBD>? zFTP_upload_file()
|
||||
** Descriptions: upload the file to FTP server
|
||||
** input parameters<EFBFBD>? ftp, path, file_name
|
||||
** output parameters<EFBFBD>? file_size
|
||||
** Returned value: zftp_client
|
||||
*********************************************************************************************************/
|
||||
int zFTP_upload_file(zftp_client* ftp, char* file_name);
|
||||
|
||||
/*********************************************************************************************************
|
||||
** Function name<EFBFBD>? zFTP_quit()
|
||||
** Descriptions: ftp logout and realse the zftp_client
|
||||
** input parameters<EFBFBD>? ftp
|
||||
** output parameters<EFBFBD>? None
|
||||
** Returned value: RT_EOK
|
||||
*********************************************************************************************************/
|
||||
int zFTP_quit(zftp_client* ftp);
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue