diff --git a/APP_Framework/Applications/app_test/test_ftpclient_final/test_ftpclient.c b/APP_Framework/Applications/app_test/test_ftpclient_final/test_ftpclient.c index 619517e48..fbd6a80fd 100644 --- a/APP_Framework/Applications/app_test/test_ftpclient_final/test_ftpclient.c +++ b/APP_Framework/Applications/app_test/test_ftpclient_final/test_ftpclient.c @@ -227,8 +227,7 @@ int Download(char *name) int Upload(char* name) { int data_fd = socket(AF_INET, SOCK_STREAM, 0); - int len = 5000; - char* buf = malloc(len); + char* buf = malloc(5000); printf("uploading file %s\r\n", name); int ret; uint8_t addr[4]; @@ -238,6 +237,7 @@ int Upload(char* name) closesocket(data_fd); return -1; } + struct sockaddr_in tcp_sock; tcp_sock.sin_family = AF_INET; tcp_sock.sin_port = htons(port); tcp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(addr[0],addr[1],addr[2],addr[3])); @@ -265,19 +265,24 @@ int Upload(char* name) return -1; } - int size = fread(buf, 1, sizeof(buf), file); + fseek(file,0,SEEK_END); + int len = ftell(file); + fseek(file,0,SEEK_SET); + + int size = fread(buf, 1, len, file); if (size == -1) { printf("failed to read data\n"); return -1; } fclose(file); - ret = send(data_fd, buf, len); + ret = send(data_fd, buf, len,0); closesocket(data_fd); ret = RecvRespond(recvBuffer, 1024); if (ret != 226) { return -1; } + printf("success!\n"); return 0; }