您好,欢迎光临本网站![请登录][注册会员]  
文件名称: ftp客户端ftpclient纯C语言winsock实现socket编程
  所属分类: Web开发
  开发工具:
  文件大小: 13kb
  下载次数: 0
  上传时间: 2009-07-13
  提 供 者: baigu*****
 详细说明: 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 fail!\n");closesocket(ds);return -1;} r2=0;r3=0;r4=0;bsnum=0;brnum=0;wi=1; while(wi) { memset(file,'\0',FNUM); r=fread(file,sizeof(char),FNUM,fp); if(r==0){closesocket(ds);wi=0;break;} brnum=brnum+r; r3=r; printf("read %8d bytes! have read %16d bytes!\r",r,brnum); do { r2=send(ds,file,r3,0); if(r2==SOCKET_ERROR){printf("send file error!");closesocket(ds);return -1;} bsnum=bsnum+r2; r3=r3-r2; printf("send %8d bytes! have sended %16d bytes!\r",r2,bsnum); }while(brnum>bsnum); }/*while*/ printf("\n"); switch(printmess()) { case 425: case 426: case 451: case 551: case 552:closesocket(ds);fclose(fp);return -1; case 250: case 226:fclose(fp);return 0; default:return 0; } }/*stor*/ int retr() { char filename[256]; unsigned long fsize,wfsize; int r2,wi; SOCKET ds; FILE *fp=NULL; 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); ds=createDataSocket(); if(ds==-1)return -1; 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(ds);closesocket(ts);sys=0;return 421; case 530:closesocket(ds);sys=1;return -1; case 500: case 501: case 504: case 226:closesocket(ds);return -1; case 200:break; default:closesocket(ds);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 530:closesocket(ds);sys=1;return -1; case 450: case 500: case 501: case 550:closesocket(ds);return -1; case 125: case 150:break; default:closesocket(ds);return -1; } set(); system(setpath); fp=fopen(filename,"wb"); if(!fp){printf("create file fail!\n");closesocket(ds);printmess();return -1;} wi=1;fsize=0;wfsize=0; while(wi) { memset(file,'\0',FNUM); r=recv(ds,file,FNUM,0); if(r==SOCKET_ERROR) { printf("file recv error!\n"); closesocket(ds); fclose(fp); return -1; } fsize=fsize+r; if(r==0){wi=0;break;} printf("receive %8d bytes! have received %16d bytes!\r",r,fsize); r2=fwrite(file,sizeof(char),r,fp); fflush(fp);/*这里是关键*/ wfsize=wfsize+r2; printf("write %8d bytes!have written %20d bytes!\r",r2,wfsize); }/*while*/ printf("\n"); switch(printmess()) { case 425: case 426: case 451:closesocket(ds);fclose(fp);return -1; case 250: case 226: closesocket(ds); wi=1; while(wi)if(fclose(fp)==0)wi=0;return 0; default:return 0; } }/*retr()*/ 以下代码请下载本程序。VC++6.0编译通过 ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: ftp client 客户端 C socket
 输入关键字,在本站1000多万海量源码库中尽情搜索: