ftp程序的设计 第2页|网络概论课程设计报告|报告
FTP核心程序
switch(cmdbuf[0])
{
case 'c':
{
memset(cmdbuf,0,20);
recv(AcceptSocket, cmdbuf, 20, 0);
Sleep(5);
chdir(cmdbuf);
closesocket(AcceptSocket);
}
break;
case 'd':
{
bWorking = finder.FindFile("*.*");
while (bWorking)
{
bWorking = finder.FindNextFile();
memset(sendbuf,0,50);
}closesocket(AcceptSocket);
}break;
case 'g':
{
FILE *p;
char buffer[1024];
memset(buffer,0,1024);
recv(AcceptSocket,sendbuf,strlen(sendbuf)+1,0);
p=fopen(sendbuf,"rb");
if(p==NULL)
{
send(AcceptSocket,"1",strlen("1")+1,0);
}
else
{
send(AcceptSocket,"0",strlen("0")+1,0);
while(fread(buffer,sizeof(char),sizeof(buffer),p)!=NULL)
{
send(AcceptSocket,buffer,sizeof(buffer),0);
}
}
fclose(p);
closesocket(AcceptSocket);
}
break;
case 'p':
{
FILE *p;
char buffer[1024];
memset(buffer,0,1024);
recv(AcceptSocket,sendbuf,strlen(sendbuf)+1,0);
p=fopen(sendbuf,"wb");
// while(recv(AcceptSocket,buffer,sizeof(buffer),0)!=NULL)
// {
// fwrite(buffer,sizeof(char),sizeof(buffer),p);
// }
while(1)
{
int ret;
ret=recv(AcceptSocket,buffer,sizeof(buffer),0);
if(ret==0)
{
memset(buffer,0,1024);
break;
}
fwrite(buffer,sizeof(char),sizeof(buffer),p);
}
fclose(p);
closesocket(AcceptSocket);
cout<<"over";
}
break;
case '?':
{
memset(sendbuf,0,50);
youerw.com
send(AcceptSocket,sendbuf,strlen(sendbuf)+1,0);
closesocket(AcceptSocket);
}break;
case 'q':break;
default:
{
cdpath=getcwd(NULL,0);
end=strlen(cdpath);
memset(sendbuf,0,50);
for(int i=begin;i<end;i++)
{
sendbuf[i-begin]=cdpath[i];
}
send(AcceptSocket,sendbuf,strlen(sendbuf)+1,0);
Sleep(5);
closesocket(AcceptSocket);
}
break;
}
///////////
}
// No longer need server socket
closesocket(AcceptSocket);
closesocket(ListenSocket);
cout<<"end"<<endl;
WSACleanup();
return 0;
}
上一页 [1] [2] [3] 下一页
ftp程序的设计 第2页下载如图片无法显示或论文不完整,请联系qq752018766