update ftpclient

This commit is contained in:
Ambrumf 2023-10-17 01:46:26 +08:00
parent 4b3f4ce773
commit ee8d4cc63a
1 changed files with 9 additions and 4 deletions

View File

@ -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;
}