我在C代码下实现了一个ftp服务器,我在list函数中遇到了一些麻烦 [英] I am implementing an ftp server under C code and I am having some trouble in the list function
本文介绍了我在C代码下实现了一个ftp服务器,我在list函数中遇到了一些麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
static int list( int ctrlfd, char * cmdline)
{
char buf [BUFSIZ];
int n;
int fd,count;
// 接受被动连接
fd = accept(pasv_socket,NULL,空值);
close(pasv_socket);
FTP_CHECK_LOGIN();
ftp_send_resp(ctrlfd, 150 );
system( dir> tmp.txt);
FILE * fin = fopen( tmp.txt, r); // 打开tmp.txt文件
char temp_buffer [ 80 ];
while (!feof(fin))
{
// 从缓冲区读取
count = fread(temp_buffer, 1 ,的sizeof 跨度>(temp_buffer),翅片);
// 写入套接字文件描述符
if (写(fd,temp_buffer,count)!= count)
printf( c'est un problem);
printf( 我只是在试着%s ------------- - \ n,temp_buffer);
}
fclose(fin);
close(fd);
ftp_send_resp(ctrlfd, 226 );
return 1 ;
}
我的尝试:
函数列表必须从目录中读取文件名,然后通过套接字将它们传递给ftp客户端
所有打印都被接受并且一切都是正确的问题是文件列表没有显示在我的filezilla中可能是数据类型的问题
我甚至在环回接口上尝试过wireshark数据正在发送!!!
如果有人知道这个问题的解决方案,请帮助我
解决方案
< blockquote>问题在于系统中的dir应该是ls - l
system(ls -l> tmp.txt );
static int list(int ctrlfd, char *cmdline)
{
char buf[BUFSIZ];
int n;
int fd,count;
//accepting the passive connection
fd = accept(pasv_socket, NULL, NULL);
close(pasv_socket);
FTP_CHECK_LOGIN();
ftp_send_resp(ctrlfd, 150);
system("dir > tmp.txt");
FILE *fin=fopen("tmp.txt","r");//open tmp.txt file
char temp_buffer[80];
while (!feof(fin))
{
//reading from buffer
count = fread(temp_buffer,1,sizeof(temp_buffer),fin);
//writing to the socket file descriptor
if(write(fd,temp_buffer,count) != count )
printf("c'est un problem");
printf("I am just tsting %s -------------- \n",temp_buffer);
}
fclose(fin);
close(fd);
ftp_send_resp(ctrlfd,226);
return 1;
}
What I have tried:
the function list must read from the directory the file names and then passes them to the ftp client through the socket
all the printing is accepted and all is correct the problem is that the file list is not showing in my filezilla maybe it is a problem of data type
I even tried wireshark on my loopback interface and the data is being sent!!!
please if anyone knows a solution to this problem please help me
解决方案
the problem was with dir in system it should have been ls - l
system("ls -l> tmp.txt");
这篇关于我在C代码下实现了一个ftp服务器,我在list函数中遇到了一些麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文