diff --git a/APP_Framework/Applications/app_test/Makefile b/APP_Framework/Applications/app_test/Makefile index 7cf98070b..67c64f851 100644 --- a/APP_Framework/Applications/app_test/Makefile +++ b/APP_Framework/Applications/app_test/Makefile @@ -134,7 +134,7 @@ ifeq ($(CONFIG_ADD_XIZI_FEATURES),y) endif ifeq ($(CONFIG_USER_TEST_FTPCLIENT),y) - SRC_FILES += test_ftpclient/test_ftpclient.c test_ftpclient/ftp_client/ftp_client.c + SRC_FILES += test_ftpclient/test_ftpclient.c test_ftpclient/ftp_client/ftp_client.c test_ftpclient_final/test_ftpclient_final.c endif ifeq ($(CONFIG_USER_TEST_LORA_P2P),y) diff --git a/APP_Framework/Applications/app_test/test_ftpclient/README.md b/APP_Framework/Applications/app_test/test_ftpclient/README.md index e025c7e37..c8e8f09d8 100644 --- a/APP_Framework/Applications/app_test/test_ftpclient/README.md +++ b/APP_Framework/Applications/app_test/test_ftpclient/README.md @@ -1,4 +1,4 @@ -# # 基于矽璓已实现的Lwip,在ARM上实现FTP协议的Client功能 +# 基于矽璓已实现的Lwip,在ARM上实现FTP协议的Client功能 ## 1. 简介 @@ -21,7 +21,7 @@ typedef struct ftp_client_struct }ftp_client; ``` -一共实现了 8 个函数,其中 4 个为接口函数,分别为: +一共实现了 8 个函数,其中 5 个为接口函数,分别为: - `ftp_cmd`:向 FTP server 发送指令 - `ftp_downloaddata`:从 FTP server 接收数据 diff --git a/APP_Framework/Applications/app_test/test_ftpclient/ftp_client/ftp_client.c b/APP_Framework/Applications/app_test/test_ftpclient/ftp_client/ftp_client.c index 2863c2c08..805768f1c 100644 --- a/APP_Framework/Applications/app_test/test_ftpclient/ftp_client/ftp_client.c +++ b/APP_Framework/Applications/app_test/test_ftpclient/ftp_client/ftp_client.c @@ -397,15 +397,15 @@ ftp_client *ftp_login(char *addr, char *username, char *password) hints.ai_protocol = IPPROTO_TCP; /* Connect to control port */ - if (getaddrinfo(ftp->server_ip, ftp->control_port, &hints, &result) != 0) goto __exit; + if (getaddrinfo(ftp->server_ip, ftp->control_port, &hints, &result) != 0) goto __exit; for (cur = result; cur != NULL; cur = cur->ai_next) { - fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol); - if (fd < 0) continue; - if (connect(fd, cur->ai_addr, cur->ai_addrlen) == 0) { - ftp->control_socket = fd; - break; - } + fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol); + if (fd < 0) continue; + if (connect(fd, cur->ai_addr, cur->ai_addrlen) == 0) { + ftp->control_socket = fd; + break; + } } freeaddrinfo(result); @@ -517,12 +517,12 @@ int ftp_downloadfile(ftp_client *ftp, char *file_name) int f = PrivOpen(name, O_RDWR|O_CREAT); /* Read the file */ while(file_size > file_pos) { - if (ftp_downloaddata(ftp->data_socket, 10000, filebuf, 16, &getlen) == 0) { + if (ftp_downloaddata(ftp->data_socket, 10000, filebuf, 128, &getlen) == 0) { if (getlen) { ret = PrivWrite(f, filebuf, strlen(filebuf)); if (ret < 0) { printf("write failed,error:%d\n", ret); - return ret; + goto __exit; } } else { ret = -1; @@ -559,7 +559,6 @@ int ftp_uploadfile(ftp_client *ftp, char *file_name) int getlen = 0; int file_pos = 0; int port = 0; - int file_size = 0; char filebuf[128] = {0}; @@ -609,11 +608,20 @@ int ftp_uploadfile(ftp_client *ftp, char *file_name) goto __exit; } - /* TODO: update file_size */ + char name[64]; + sprintf(name, "/%s", file_name); + int f = PrivOpen(name, O_RDONLY); + if (f < 0) { + printf("Open file error.\n"); + return -1; + } - while(file_size > file_pos) { - /* TODO: read file and update filebuf */ - if (ftp_uploaddata(ftp->data_socket, filebuf, 128, &getlen) == 0) { + while((ret = PrivRead(f, filebuf, 128)) != 0) { + if (ret < 0) { + printf("read failed.\n"); + goto __exit; + } + if (ftp_uploaddata(ftp->data_socket, filebuf, ret, &getlen) == 0) { if (!getlen) { ret = -1; goto __exit; @@ -676,5 +684,6 @@ int ftp_quit(ftp_client *ftp) ftp->control_socket = -1; free(ftp); + ftp = NULL; return 0; } \ No newline at end of file diff --git a/APP_Framework/Applications/app_test/test_ftpclient/ftp_client/ftp_client.h b/APP_Framework/Applications/app_test/test_ftpclient/ftp_client/ftp_client.h index e1dae4247..83663f02d 100644 --- a/APP_Framework/Applications/app_test/test_ftpclient/ftp_client/ftp_client.h +++ b/APP_Framework/Applications/app_test/test_ftpclient/ftp_client/ftp_client.h @@ -7,7 +7,7 @@ #include -#define CONTROL_PORT "21" +#define CONTROL_PORT "9991" #define NOCMD 0 #define PASV 1 @@ -36,5 +36,6 @@ typedef struct ftp_client_struct ftp_client *ftp_login(char *addr, char *username, char *password); int ftp_downloadfile(ftp_client *ftp, char *file_name); +int ftp_uploadfile(ftp_client *ftp, char *file_name); int ftp_changedir(ftp_client *ftp, char *dir); int ftp_quit(ftp_client *ftp); \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/resources/ethernet/LwIP/include/lwip/opt.h b/Ubiquitous/XiZi_IIoT/resources/ethernet/LwIP/include/lwip/opt.h index a304c67c2..bd30fef22 100644 --- a/Ubiquitous/XiZi_IIoT/resources/ethernet/LwIP/include/lwip/opt.h +++ b/Ubiquitous/XiZi_IIoT/resources/ethernet/LwIP/include/lwip/opt.h @@ -529,7 +529,7 @@ * (only needed if you use the sequential API, like api_lib.c) */ #if !defined MEMP_NUM_NETCONN || defined __DOXYGEN__ -#define MEMP_NUM_NETCONN 4 +#define MEMP_NUM_NETCONN 20 #endif /**