[comp.unix.questions] Running 'ftp' from a program using 'popen'?

toppin@melpar.UUCP (Doug Toppin) (10/10/90)

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

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (10/11/90)

In article <205@melpar.UUCP> toppin@melpar.UUCP (Doug Toppin) writes:
> I am using 'popen()' to run 'ftp' and am then writing the appropriate
> command to the file pointer returned by 'popen()'.

Deja vu. Don Libes' expect program should be able to handle all the
automation you need.

expect is described in the paper "expect: Curing Those Uncontrollable
Fits of Interaction" by Don Libes, Proceedings of the Summer 1990
USENIX Conference, Anaheim, CA, June 11-15, 1990.  More examples and
discussion, specifically designed for system administrators, are in
"Using expect to Automate System Administration Tasks" by Don Libes,
Proceedings of the 1990 USENIX Large Systems Administration Conference
(LISA) IV, Colorado Springs, CO, October 17-19, 1990.

expect may be ftp'd as pub/expect.shar.Z from durer.cme.nist.gov.  If
you cannot ftp, you may request email copies by mailing to "library@
cme.nist.gov".  The contents of the message should be (no subject
line) "send pub/expect.shar.Z".  Once you have retrieved the system,
please read the INSTALL file.  The paper(s) mentioned above can be ftp'd
separately as pub/expect.ps.Z and pub/expect-sysadm.ps.Z.

---Dan