cin>>Dir;
client->setCommand("CWD",Dir);
client->sendCommand();
client->receiveCommand();
}
elseif(strcmp(Command,"retr")==0||strcmp(Command,"RETR")==0)
{
char*filename=newchar[512];
memset(filename,NULL,512);
/************************************
下载模块
************************************/
client->setCommand("PASV");
client->sendCommand();
client->receiveCommand();
client->getPort();
client->setCommand("TYPE","I");
client->sendCommand();
client->receiveCommand();
client->interlizeDataSocket();
cout<<"Pleaseinputthenameyouwanttodownload:
";
cin>>filename;
client->setCommand("RETR",filename);
client->sendCommand();
client->receiveCommand();
client->receiveData(filename);
client->receiveCommand();
deletefilename;
}
elseif(strcmp(Command,"stor")==0||strcmp(Command,"STOR")==0)
{
char*filename=newchar[512];
memset(filename,NULL,512);
/************************************
上传模块
************************************/
client->setCommand("PASV");
client->sendCommand();
client->receiveCommand();
client->getPort();
client->setCommand("TYPE","I");
client->sendCommand();
client->receiveCommand();
client->interlizeDataSocket();
cout<<"PleaseinputthenameyouwanttoUPload:
";
cin>>filename;
client->setCommand("STOR",filename);
client->sendCommand();
client->receiveCommand();
client->sendData(filename);
client->receiveCommand();
deletefilename;
}
elseif(strcmp(Command,"dele")==0||strcmp(Command,"DELE")==0)
//进入删除文件的程序代码段
{
char*filename=newchar[512];
memset(filename,NULL,strlen(filename));
cout<<"PleaseinputthefilenameyouwanttoDelete:
";
cin>>filename;
client->setCommand("DELE",filename);
client->sendCommand();
client->receiveCommand();
deletefilename;
}
elseif(strcmp(Command,"rmd")==0||strcmp(Command,"RMD")==0)
//进入删除目录的程序代码段
{
memset(Dir,NULL,strlen(Dir));
cout<<"PleaseinputtheDirectyouwanttoDelete:
";
cin>>Dir;
client->setCommand("RMD",Dir);
client->sendCommand();
client->receiveCommand();
}
elseif(strcmp(Command,"mkd")==0||strcmp(Command,"MKD")==0)
//进入修改文件的程序代码段
{
memset(Dir,NULL,strlen(Dir));
cout<<"PleaseinputtheDirectyouwanttoMake:
";
cin>>Dir;
client->setCommand("MKD",Dir);
client->sendCommand();
client->receiveCommand();
}
elseif(strcmp(Command,"QUIT")==0||strcmp(Command,"quit")==0)
//进入退出文件的程序代码段
{
break;
}
else
{
cout<<"NosuchCOMMAND!
!
";
}
}
}
}
else
cout<<"ErrorYoucannotloginin."<cout<<"Cleaningsystemresource"<//delete[]userName;
//delete[]Direct;
//deleteclient;
cout<<"ExitingGoodbye"<system("pause");
}
5、测试与结果
6、总结与分析
本次实验达到了本项实验的初始目的和要求。
通过这次实验,我对socket的网络编程有了更清楚的认识,懂得了它怎么联网并对ftp上的文件的上传,下载等操作,知道了怎么把书上的知识在实际中的运用。
不过由于对界面的设计还不是很了解,还不能很好地把界面设计出来。
希望下次能做得更好!
七、参考资料
①《现代网络技术教程——自顶向下分析与设计》
②XX百科
③XX知道