课程设计 F TP的设计与实现
/******* *****************/
include<winsock2 h>
#nlue < tdio >
in ude <s l b h>
#pragma commen (lib,"ws2_32 lib )
#define DFAULT_T 2302
#define DEFAUL_BUFFER
#defne EFAULMESGE "Th s i a test o the erge y \ boadcast g ste"
ar szerveri[128 , //Srer t cnnec szMe sage[1 24] //Messae nd to severin iPo t = FAULT_ORT;/Port on serer to nnect to
/WRD dCount =DEALT_CONT /Numbe of times to se me sgeBObSndnly =FASE /S data ony;don't reeiveint di fun ;int ge fun();int putfn();
nt w n );int cf () int mdfun();int delfun();in usa u );vi usae()
{printf "usag: c ent [-p:] [- :IP n:x] [o] );pr ntf( -p x Remot po t d n");pritf();
rintf );pr tf(" - Snd ms ges ny;don't re ve\n");
ExitProcess(1);
}
oi Val dateAg ( nt arc, car**argv)
{
t i;fo (i= 1;i<argc; i+
{i ((argv i][]= '- ) | | (rv[i] 0]==''))
{
witch ( lw a gv[i [1])
{cse
f(s rl e(a i])> 3)
Prt=aoi(&arg[i][3] i (st n(arg[i )> 3)strcp( e ver p,&argv[i][]);ca i (s rl en(argv[i] >3)
//dwC nt= tol(&argv[i [3]);
abSedOl TREbrakdefau t:u age( ;break;
}
}
}
}int ma n n a gc
{
WSADATA ws;
C KT Cli t;cha sBufer[DEFULT_BUFE R];
nt ret;
//usin e nt ;
//it j struct socaddr_in srerstrc ostent *hst= NUL;cha choice[] choic2[40 ;
//Prse te comman li ad oad Winok
/a gv 1]="s 127 0 ";strcy( zServerip,&rv[1][3]);
//Vlidatergs ar , a gv);if(WSAS artu(KEWD(2 2 &wd) =0)
pritf("ai ed to loainsok libra y!\");
etrn 1;
}
strcpy( Me sage, DFULT_MSAGE);
//
/ rea e th ocket, nd atte o connet to h se er//
Client= socke (AFIT,S OC_STREAM IRT O_TCP ;if s ient =INVALIOC KE)
{
rintf("socet ) faile:%d\n" AG astrror( ;
eturn ;
}serer n_fmil =AFINET;
erer inprt=hons( ort);p ntf(;server s n_add addr=int_ad(s ervri)
/
/If the supplied erver address wasn't in th f m
//if( erver s _addr s_ddr==INAD_NONE)
ho t= e hostbynae s erv ip);
f(host==NLL)
{
rintf(;return 1;
CopyMemo & erver in_add ,host->_adr st 0],ho t->h_len h);
}if (con (sCl en, (struct sockaddr )srersizef( r ) == SOET_ERROR)
{pr ntf("onnect ) fa led %d ,WSAGe Lastr or ));retur 1;
}
//显示接通信息
//
//
//for(j=0 j<;j++)
//
{ret=rec(slin , szBfer DEFAUTBUFFER, ;i ret0) //Grcful clo er un0;
lse if( et == SOCKET_EOR)
p n f( rec() i d:%\n" WSAtLstEr or( ;r e trn ;
szBuffe [ t] '\0';pri ("%s\ ,szBufer);if(ret<1
{
et cv( Client, zuff DFAULT_UR,0) if(ret =0) // racef lose
etur 0e e if (ret= OCKETERO)
{
/printf("recv() fa ed:%dn SGe Las Er or ));retrn
}szB fer ret '0';
rin "s\n",szBuffer);
}
/printf("DEAULUFFE=%\ ,DEFA_BUFFE);
}whi l e 1
{puts("------------------------");prin ("ft> ;scan (" ch ce);if(strcm hic, i ",3)==0| | tr m(h ce,"D ,2)=0){dirfun(sClient ;contine
}el se st ncmp choi c e,"pd",3 =0| | tr mp(c i ,"PWD" 3)=0{pwdfun s e );
ntine;
}e e if(st ncmp(cho ce, " )=0)
{u fun( Cliet)
con iu;
}
l (st ncm(hi c e,"qu t",4 == | st nmp(choie "QUI",2)==0){
reak;
}s nf ;i f(st ncmp(c i c e,"get",3 =0 | rncmp(c i c,"GET" 3)==0)
{g fun(sC nt,choic );con inue;
}
lse if(strncp(choic,"pt ,3)==0| | s ncp(choie "PUT",3 ==)
{put u(sClien ,ch 2 ;cntinue;
e e if(strncm( oice " ",)==0| | st cmp(c ice, CD" 2)==)cdfun( Clint,ho c2 co iue;
}e s i trnc( oie,"m",)= | | trcmp(coi c e, D" 2 =0){mdfun( Cl en coie2 ;continue;
}e se if(str mp(co ce,"del" 3)= | | trncmp(h e "DL",)==0){delfun sClient choice cotiue;
e
uts("输入错误请重新输入 );
flu sh s di);fflsh(s n) printf "\");pri f \n")
}c ose c t(sCl et ;
WSAlanup();retur ;
n d rfun(OCKET sCl ent)
in re ;cha *MG="di ";char sfer[ ];s rcpy(sMssage, MG);ret= send( Clint ;if(rt= 0)return ;e e if(rt==SCKE_EROR
rintf("send() fa l :%d\n", WSGetLatErrr()) retun ;
}
//printf "Se d s\n , ret);
//rin f("bSendOnl%d\n",S endOnly);while(!bS endOnly)
/读取流并显示
// e = recv(sl nt, zuffer,8, 0);
//p ntf("%s", zBuffe );
e =recv(sC ient, szBuff ,8, ) if ret ==0 // acefu lsreturn 1 else i ( et= SOCKTERR)
{prin f "recv ) failed: d\n SAGetLstError ) ;
etun 1;
}
zBffe [ret = '0';if( trncp(sBuffer "226 Clse",s rlen 2 lo e") ==0)
{break;
}prit ("%s",szBuffr) if strcp(szB fer," 00 S tax e rr",strlen("500 Snta error"))=){bra;
}
}rtun 0;
}int un(SOET Client,ha [0 )
{int rt;
ILE*fr e;car szfer[8];szMes ae[0]='0' strca (sMessage, "ge $");
// t( zMessage, \ );stra sMs a ,)
/pitf("G[4]%c\n ,szMes g [4]);
/sMessag [0]=;
//
/szes age[4]=;//
//szMessge[8]=;
e = nd(sClient, sMss , strlen(szMe sae)+1,0);
f ( et==0)return 1;
ls if ( et== OCKET_ERR)
{
rintf( end() fa le:%d\n", WSAG astr or()) rtu 1
}print ("Sen % y es\n , ret) ret= recv sClient, szBufe , 0,0);
*if ret==0) /Grace ul clsebrak;
lse i (rt= OCKET_ERROR)
{printf("rec() fi ed:\n , WSAetLastErr ());brak
}*/
zf r[ret = '\0
ntf ;i (st cmp( suffer,"1 5 Transferin ",s rlen(" 5 T nsfer ng " )=0)
f( ( e=foe( "w")) == ULL)
{pr n f("opn rr");
et n 1;
}pitf bS enOny=dn ,bS endnly);while !bS endOnl
{
/读取流并显示rt= rcv(sCliet, szBufer,80 0);if(ret=0) // Graeful cl eretun ;else if(rt=SOKT_ERRR)
{
rint ("recv ) fai ed %d\n",WAGetLastEr or());rturn 1
szufer[ret ='\0 ;
/printf "% ", zBufer ;i ( rcp( zBuffer,"22 Transfr ,st len("22 ansfer ))==0){b a;
if( rncp sBuffr,"500 Synta error",s rlen(" 00 yn ax rror") ==0){bra;
fpritf(fpre,"%s" sBuff );
}print ("% \n",suffe );
cl p );
}retrn 0;
int putfn(SOCE sClient,cha 0])
{int et;//in i;
FILE f e;/char ;
/char SG="gt\0me txt";car szBufe [8] ep_buffe [0];
/spr n f(szMe age "et0"," e txt\0 ) sMessage 0 ='0';st cat( Me sage strcat szMssge );ret =sen( Client, zMessage, st en(szessge)+1,0);
if(ret== retu 0;el e if (rt= SCKETERROR)
{printf("snd() failed: %d", WetLas Erro() ;retr ;
}
/prin f("Sen % by es\", e ;
// m tx ";pintf("\n",);if (fpse=fp , r )) =NULL)
pintf("pen r r");return
}e s
{p t ("h fun, eady t trans er\n",);
/i=0wh ( e t s(tp_bffe r,80, s e) N ULL)
{sprintf( zBu , s", emp_ufe ;snd(sClin , sBffer, ,0);
}
}sprin f( zuffr "226 Trnsfer cp ete \r\n ;ret =snd(sC ient, zBu er, strl zBufr), 0);fclos(fp e r ur 0;
}it pwdun(SOCET sClien)
{int r ;char MSG="pwd$";chr sBufe [160];s rcp( zMess e,S ;
t en sClien ; f( et=0)rtur 1;
lse f(rt =SK_ERROR)
{pri f send() fa ed d\n",WSAGtas Error());
etur 1;
运作了18年的德国老牌机房contabo在继去年4月开办了第一个美国数据中心(中部城市:圣路易斯)后立马在本月全新上马两个数据中心:纽约、西雅图。当前,为庆祝美国独立日,美国三个数据中心的VPS全部免除设置费,VPS本身的配置很高,价格适中,有较高的性价比!官方网站:https://contabo.com/en/SSD VPSKVM虚拟,纯SSD阵列,不限制流量,自带一个IPv4内存CPUSSD带...
BuyVM商家算是一家比较老牌的海外主机商,公司设立在加拿大,曾经是低价便宜VPS主机的代表,目前为止有提供纽约、拉斯维加斯、卢森堡机房,以及新增加的美国迈阿密机房。如果我们有需要选择BuyVM商家的机器需要注意的是注册信息的时候一定要规范,否则很容易出现欺诈订单,甚至你开通后都有可能被禁止账户,也是这个原因,曾经被很多人吐槽的。这里我们简单的对于BuyVM商家新增加的迈阿密机房进行简单的测评。如...
欧路云新上了美国洛杉矶cera机房的云服务器,具备弹性云特征(可自定义需要的资源配置:E5-2660 V3、内存、硬盘、流量、带宽),直连网络(联通CUVIP线路),KVM虚拟,自带一个IP,支持购买多个IP,10G的DDoS防御。付款方式:PayPal、支付宝、微信、数字货币(BTC USDT LTC ETH)测试IP:23.224.49.126云服务器 全场8折 优惠码:zhujiceping...