Running 'ftp' from a program using 'popen'? (long)

Doug Toppin toppin at melpar.UUCP
Wed Oct 10 07:37:23 AEST 1990


I am running SCO Xenix 2.2.3 on the 286 with the NRC implementation
of TCP/IP (Fusion).
I need to transfer some files to another machine in which I
cannot port ANY software.
I am going to have to transfer the files by having my software
run 'ftp' and send the commands to it.
I am using 'popen()' to run 'ftp' and am then writing the appropriate
command to the file pointer returned by 'popen()'.
I am able to get the files to be sent with no problem but I have
not been able to read any responses from 'ftp'.
If I 'popen' with "rw" 'ftp' doesn't work at all.
I have to do the following (with appropriate error checking in my stuff):
    FILE *fptr;
    fptr = popen("ftp -n hostname", "w"); /* run ftp (noninteractive option) */
    fprintf(fptr, "user login passwd\n"); /* login to remote machine */
    fprintf(fptr, "put sourcefile\n");    /* tell ftp to put the file */
    pclose(fptr);                         /* done with ftp */
If I do this the transfer works fine but I cannot get any feedback to
my program from 'ftp'.
If I redirect 'ftp's output to either a file or a named pipe then
only thing I get in either are 3 newlines.
If I don't redirect it at all then the correct output appears
on my screen.
There is no user on this system so I must, under program control,
detect a good or bad send.
If you have any suggestions or a working example please post
it or drop me a line.
My system does not have 'rcopy' or any other neat command.
'ftp' is the only thing I have to work with.
Please do not suggest using anything other than 'ftp' because
we cannot put any software on the destination machine.

thanks
Doug Toppin
uunet!melpar!toppin



More information about the Comp.unix.questions mailing list