LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C -communicating with system("ftp"); using "program|ftp>>myfifo" probably (https://www.linuxquestions.org/questions/programming-9/c-communicating-with-system-ftp-%3B-using-program%7Cftp-myfifo-probably-305148/)

hansschmucker 03-23-2005 01:19 PM

C -communicating with system("ftp"); using "program|ftp>>myfifo" probably
 
I've got a very simple program here for which I can't find a reasonable explanation. I need a program which generates a static index for an FTP server... generally not much of a problem... I just use system("cat script|ftp ftp://user:pass@server.com/path/>output.file"); with "script" containing nothing more then a simple "ls" and parse the resulting output.log.

Problem is, that requires me to re-login for each directory which takes some time, so I want to keep ftp running all the time and just issue some commands to it

Code:

int main(int argc, char *argv[])
{       
        UInt32 i;
        IndexType FileIndex;
        if(argc==1){
                fprintf(stderr,"Please start with\n mkindex ftp://user:pass@server.com/path/\n");
                return 1;
        }
        if(argv[1][1]!='i'){
                fprintf(stderr,"self launch");
                system(Str_Merge6(argv[0]," -i ",argv[1],"|ftp ",argv[1], "\n"));
                return 1;
        }
        fprintf(stdout,"ls\n ");
}

Problem is that ftp quits as soon as there are no more commands coming from the main program, instead of sitting there and waiting for the next command. If I issue a cd and an ls command while ftp is still busy loggin in, it'll execute both, but exit immediately afterwards, like it would get an EOF from the input. Any ideas how to solve this? Any help would be highly appreciated!

itsme86 03-23-2005 01:39 PM

I think popen() would be a much better solution to your problem. Check out the man page for it.


All times are GMT -5. The time now is 06:13 PM.