📄 pasvlist.c
字号:
#include "MyFtpSvr.h"
void Pasv_List(int sockControl,int sockData,char *path)
{
char szSvrMsg[64];
char list[128]={0};
DIR *dp;
char *time;
char mode[12]={0};
struct dirent *dirp;
struct stat buf;
strcpy(szSvrMsg,
"150 Here comes the directory listing.\r\n");
Send(sockControl,szSvrMsg,strlen(szSvrMsg),0);
chdir(path);
dp=opendir(path);
while((dirp=readdir(dp))!=NULL)
{
if(*dirp->d_name!='.')
{
stat(dirp->d_name,&buf);
if(S_ISREG(buf.st_mode)) mode[0]='-';
if(S_ISDIR(buf.st_mode)) mode[0]='d';
if(S_ISCHR(buf.st_mode)) mode[0]='c';
if(S_ISBLK(buf.st_mode)) mode[0]='b';
if(S_ISFIFO(buf.st_mode)) mode[0]='p';
if(S_ISLNK(buf.st_mode)) mode[0]='l';
if(buf.st_mode&S_IRUSR) mode[1]='r';
else mode[1]='-';
if(buf.st_mode&S_IWUSR) mode[2]='w';
else mode[2]='-';
if(buf.st_mode&S_IXUSR) mode[3]='x';
else mode[3]='-';
if(buf.st_mode&S_IRGRP) mode[4]='r';
else mode[4]='-';
if(buf.st_mode&S_IWGRP) mode[5]='w';
else mode[5]='-';
if(buf.st_mode&S_IXGRP) mode[6]='x';
else mode[6]='-';
if(buf.st_mode&S_IROTH) mode[7]='r';
else mode[7]='-';
if(buf.st_mode&S_IWOTH) mode[8]='w';
else mode[8]='-';
if(buf.st_mode&S_IXOTH) mode[9]='x';
else mode[9]='-';
time=ctime(&buf.st_ctime);
sprintf(list,"%s %d %d %d %d %.12s %s\n",
mode,(int)buf.st_nlink,
buf.st_uid,buf.st_gid,
(int)buf.st_size,4+time,dirp->d_name);
Send(sockData,list,strlen(list),0);
memset(list,'\0',sizeof(list));
}
}
strcpy(list,"\r\n");
Send(sockData,list,strlen(list),0);
strcpy(szSvrMsg,"226 Directory send OK.\r\n");
Send(sockControl,szSvrMsg,strlen(szSvrMsg),0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -