Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
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
Posted
Updated 14-Mar-16 10:21am
Comments
Jochen Arndt 12-Mar-16 11:08am    
As far as I remember there must be a 2xx status line (e.g. "200 PORT command successful.") before the 150 status line. Maybe the FTP client (FileZilla) receives the data but does not display anything due to the missing 2xx status line.
KarstenK 13-Mar-16 5:16am    
The write isnt correct implemented. There can be multiple write needed if you have a big input file. I would implement really more error checking ...
Member 12252762 14-Mar-16 16:02pm    
hello guys thank you for your reply , it turned out to be that the problem is from the system("dir > tmp.txt"); I changed dir to ls -l and it worked like a charm up till now thank you

1 solution

the problem was with dir in system it should have been ls - l


system("ls -l> tmp.txt");
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900