⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientrequest.c

📁 linux先ftp客户端,实现文件上传下载,建立目录,实现互联网文件共享
💻 C
字号:
#include "MyFtpSvr.h"void Recv(int s, char *buf, int len, int flags){	int iRet;	iRet=recv(s,buf,len,flags);	if(iRet<0)	{		perror("recv faild");		return;	}	}void UpLoadRegFile(char *szSvrMsg,int sockControl,int sockData){	char RecvDataBuf[1024]={0};	char szMsg[64]={0};	char *FilePath=NULL;	int nrecv;	FILE *fpFile=NULL;	FilePath=FindFilePath(szSvrMsg);	fpFile=fopen(FilePath,"wb+");	if(fpFile==NULL)	{		perror("open fild");		return;	}	strcpy(szMsg,"150 Ok to send data.\r\n");	Send(sockControl,szMsg,strlen(szMsg),0);	while((nrecv=recv(sockData,RecvDataBuf,sizeof(RecvDataBuf),0))!=0)	{		fwrite(RecvDataBuf,1,nrecv,fpFile);		memset(RecvDataBuf,'\0',sizeof(RecvDataBuf));	}	fclose(fpFile);	strcpy(szMsg,"226 Directory send OK.\r\n");	Send(sockControl,szMsg,strlen(szMsg),0);}void UpLoadDirFile(char *szSvrMsg,int sockControl){	char *FilePath=NULL;	char szMsg[64]={0};	FilePath=FindFilePath(szSvrMsg);	if(mkdir(FilePath,0666)!=0)	{		if(errno!=EEXIST)		{			perror("mkdir");			return;		}	}	strcpy(szMsg,"257 file created!\r\n");	Send(sockControl,szMsg,strlen(szMsg),0);}void DeleRegFile(char *szSvrMsg,int sockControl){	assert(szSvrMsg!=NULL);	char *FilePath=NULL;	FilePath=FindFilePath(szSvrMsg);	unlink(FilePath);	strcpy(szSvrMsg,"250 Delete operation successful.\r\n");	Send(sockControl,szSvrMsg,strlen(szSvrMsg),0);}void DeleDirFile(char *szSvrMsg,int sockControl){	assert(szSvrMsg!=NULL);	char *FilePath=NULL;	FilePath=FindFilePath(szSvrMsg);	rmdir(FilePath);	strcpy(szSvrMsg,"250 Remove directory operation successful.\r\n");	Send(sockControl,szSvrMsg,strlen(szSvrMsg),0);}void Send(int s, const void *msg, size_t len, int flags){	int iRet;	iRet=send(s,msg,len,flags);	if(iRet<0)	{		perror("send faild");		return;	}}void DownLoadRegFile(char *szSvrMsg,int sockControl,int sockData){	char szBuf[256]={0};	char szMsg[64]={0};	char *FilePath;	int nread;	FILE *fp;	FilePath=FindFilePath(szSvrMsg);	strcpy(szMsg,"150 Opening BINARY mode data connection.\r\n");		Send(sockControl,szMsg,strlen(szMsg),0);	fp=fopen(FilePath,"r");	if(NULL==fp)	{		perror("fopen fild");		return;	}	while(!feof(fp))	{		nread=fread(szBuf,1,sizeof(szBuf),fp);		Send(sockData,szBuf,nread,0);		memset(szBuf,'\0',sizeof(szBuf));	}	fclose(fp);	memset(szMsg,'\0',sizeof(szMsg));	strcpy(szMsg,"226 File send OK.\r\n");	Send(sockControl,szMsg,strlen(szMsg),0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -