blob: 12e3f0935904ba2911c42a0a85845ae0bd735538 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001#include<stdio.h>
2#include<sys/socket.h>
3#include<stdlib.h>
4#include<string.h>
5#include<strings.h>
6#include<unistd.h>
7#include<netinet/in.h>
8#include<netdb.h>
9#include<errno.h>
10#include<sys/types.h>
11#include<sys/stat.h>
12#include<fcntl.h>
13#include "liblog/liblog.h"
14#include "liblog/lynq_deflog.h"
15
16
17#define SERV_PORT 21
18#define MAXSIZE 1024
19//#define MAXBUF 1024
20#define FTP_FILE_TYPE_LEN 4
21#define FTP_MAX_ASCII_LEN 1024
22#define FTPSHMPATH "/"
23#define FTPSHMID 'K'
24
25
26int error;
27char errorbuf[10];
28
29#if 1
30/*log error info */
31
32#define FTP_NET_ERROR 31 //network
33#define FTP_DNS_ERROR 32 //DNS
34#define FTP_CONNECT_ERROR 33 //connect
35#define FTP_TIMEROUT 34 //time out
36#define FTP_SERVER_ERROR 35 //server
37#define FTP_OPERATION_NOT_ALLOW 36 //operation not allow
38#define FTP_REPLAY_ERROR 37 //replay
39#define FTP_USER_ERROR 38 //user
40#define FTP_PASSWORD_ERROR 39 //pwd
41#define FTP_TYPE_ERROR 40 //type
42#define FTP_REST_ERROR 41 //rest
43#define FTP_PASSIVE_ERROR 42 //passive
44#define FTP_ACTIVE_ERROR 43 //active
45#define FTP_OPERATE_ERROR 44 //operate
46#define FTP_UPLOAD_ERROR 45 //upload
47#define FTP_DOWNLOAD_ERROR 46 //download
48#define FTP_FILE_ACTION_ERROR 47 //action error
49#define FTP_MANUAL_QUIT 48 //manual quit
50#define FTP_ERROR_FLAG 49
51#define FTP_SOCK_ERROR 50 //socket error
52#define FTP_RCV_ERROR 51 //rcv error
53#define FTP_SEND_ERROR 52 //send error
54#define FTP_CLOSE_ERROR 53 //close error
55#define FTP_READ_ERROR 54 //read error
56#define FTP_WRITE_ERROR 55 //write error
57#define FTP_LS_ERROR 55 //ls error
58
59#endif
60
61#if 1
62/***********ftp return vauil******************/
63
64#define FTP_100_INIT_WAIT_LAST_CMD 100
65#define FTP_125_TRANSFER_START 125
66#define FTP_150_OPEN_DATA_CONNECT 150
67
68#define FTP_200_COMMAND_SUCCESSFUL 200
69#define FTP_213_FILE_STATUS 213
70#define FTP_220_SERVER_READY_FOR_NEW_USER 220
71#define FTP_221_CLOSE_CONTROL_CONNECT 221
72#define FTP_226_TRANSFER_COMPLATE 226
73#define FTP_227_ENTRY_PASV_MODE 227
74#define FTP_230_USER_LOGGED_IN 230
75#define FTP_250_REQUEST_FILE_ACTION_OK 250
76#define FTP_257_PATH_NAME 257
77
78
79#define FTP_331_NAMEOK_PASS_REQUIRE 331
80#define FTP_350_FILE_OPER_OK_WAIT_NEXT 350
81
82#define FTP_421_CONTROL_LINK_SHUTDOWN 421
83#define FTP_425_CANNOT_OPEN_DATA_CONNECT 425
84
85
86#define FTP_500_COMMAND_ERROR 500
87#define FTP_501_PARAMETER_ERROR 501
88#define FTP_502_COMMAND_NOT_IMP 502
89#define FTP_503_BAD_SEQUENCE_OF_CMD 503
90
91#define FTP_530_CANNOT_LOG_IN 530
92#define FTP_532_NEED_ACCOUNT 532
93#define FTP_534_CANNOT_CONN_CAUSE_SSL 534
94#define FTP_550_FILE_CANT_FIND 550
95
96
97#endif
98
99typedef struct ftp_socket_info
100{
101 int id;
102 int index;
103 char protocol[10];
104 int session;
105 char action[10];
106
107 int control_sockfd;
108 int portnum;//port num 1~65535
109 char is_pasv_mode[225];//0:initiative 1:pasv
110 char file_type[FTP_FILE_TYPE_LEN+1];//type "A" or "I"
111 char put_opt[FTP_FILE_TYPE_LEN+1];// "APPE", "STOU", "STOR"
112 int rest; //xu chuan wei zhi;
113 char sevname[FTP_MAX_ASCII_LEN + 1];//addr :192.168.1.89;
114 char username[FTP_MAX_ASCII_LEN + 1];//user
115 char pw[FTP_MAX_ASCII_LEN + 1];//password
116 char getfilename[FTP_MAX_ASCII_LEN + 1];//get file name;
117 char getfilename_path[FTP_MAX_ASCII_LEN + 1];//get file path;
118 char putfilename[FTP_MAX_ASCII_LEN + 1];//put file name;
119 char putfilename_path[FTP_MAX_ASCII_LEN + 1];//put file path;
120 //char conmd[255];
121 char dir[1024];
122 char del_mkr_filename[1024];
123 char respond[1024];
124 int flag;
125 int flag1;
126 int modify_thread;
127 int add_thread;
128}lynq_ftp_socker_info;
129
130
131int control_sockfd;
132int login_yes;
133int f;
134char putpathname[225];
135char hoster[255];
136struct sockaddr_in servaddr;
137char rbuf[1024],rbuf1[1024],wbuf[1024],wbuf1[1024];
138int ftpshm_id;
139lynq_ftp_socker_info *FTP;
140
141int uartfd;
142int usbfd;
143//char BUF[1024];
144
145
146
147int lynq_ftp_put(int sck,char *pUploadFileName_s);
148extern int lynq_ftp_login(lynq_ftp_socker_info *FTP);
149extern void zeromery(char *a,int len);
150extern char *itoa(int value, char *string, int radix);
151extern void lynq_ftp_pwd(int control_sockfd);
152extern int strtosrv(char *str);
153extern void lynq_ftp_get(int sck, char *pDownloadFileName, int session);
154extern void lynq_ftp_rest(int control_sockfd);
155extern int cliopen(char *hoster, int port);
156extern int lynq_ftp_download(lynq_ftp_socker_info* FTP);
157extern int lynq_ftp_up(lynq_ftp_socker_info* FTP);
158int lynq_ftp_ls(lynq_ftp_socker_info* FTP);
159void lynq_ftp_cd(lynq_ftp_socker_info* FTP);
160void lynq_ftp_creat_mkd(lynq_ftp_socker_info* FTP);
161void lynq_ftp_delete_mkd(lynq_ftp_socker_info* FTP);
162void ftp_list(int sockfd, int session);
163void lynq_ftp_quit(lynq_ftp_socker_info* FTP);
164void lynq_ftp_deletefile_mkd(lynq_ftp_socker_info* FTP);
165
166
167extern void init(lynq_ftp_socker_info* FTP);
168extern int lynq_ftpshm_create( void );
169extern lynq_ftp_socker_info *ftpshm_act(int shmid);
170extern void lynq_ftpshm_deact(lynq_ftp_socker_info *shm);
171extern void lynq_ftpshm_del(int shmid);