ftp客户端ftpclient纯C语言winsock实现socket编程
/*
*本程序是2009年计算机网络课程设计作品。
*本程序参考rfc959标准。能准确与遵守此标准的服务器进行信息交互。
*本人不保留任何版权。
*本程序仅供学习研究测试使用。因使用本程序所有或部分代码所产生的任何后果,本人均不负任何法律责任。
*2009年7月13日
*/
#include
#include
#include /*system()*/
#include
#pragma comment(lib,"ws2_32.lib")
#define ONUM 512
#define MNUM 512
#define FNUM 512
#define pt
struct host
{
char ip[20];
unsigned short port;
};
SOCKET ts;
fd_set readfds;
struct timeval timeval;
struct host host;
char renum[4];
char ordertemp[ONUM];
char order[ONUM];
char ordercp[ONUM];
char mess[MNUM];
char file[FNUM];
char setpath[FNUM];
char setpathf[FNUM];
int i,door,r,sys,seti;/*i for;door switch;r receive num;sys system state;set set state*/
char *p;/*strtok*/
int printmess();
void input(char ordertemp[]);
int ftp();
int user();
int pass();
int command();
int list();
SOCKET createDataSocket();
int set();
int retr();
int stor();
int stor()
{
char filename[256];
SOCKET ds;
int wi;
int r2,r3,r4,bsnum,brnum;
FILE *fp=NULL;
set();
memset(filename,'\0',256);
memset(order,'\0',ONUM);
for(i=5;i<=200&&ordercp[i]!='\0';i++)order[i-5]=ordercp[i];
strcpy(filename,setpathf);
strcat(filename,"\\\\");
strcat(filename,order);
memset(order,'\0',ONUM);
strcpy(order,"type i\r\n");/*type i 二进制 type a ASCII*/
send(ts,order,strlen(order),0);
switch(printmess())
{
case 421:closesocket(ts);sys=0;return 421;
case 530:sys=1;return -1;
case 500:
case 501:
case 504:
case 226:return -1;
case 200:break;
default:return -1;
}
ds=createDataSocket();
if(ds==-1)return -1;
strcat(ordercp,"\r\n");
send(ts,ordercp,strlen(ordercp),0);
switch(printmess())
{
case 421:closesocket(ds);closesocket(ts);sys=0;return 421;
case 532:
case 530:closesocket(ds);sys=1;return -1;
case 450:
case 452:
case 553:
case 500:
case 501:closesocket(ds);return -1;
case 125:
case 150:break;
default:closesocket(ds);return -1;
}
fp=fopen(filename,"rb");
if(!fp){printf("read file fa
1