Re: [NEWBIE] Outside commands, FTP

From: Patrick Dughi (dughi@imaxx.net)
Date: 01/04/01


> Ok does anyone see something wrong with this?

        Yes.

> I am trying to have it upload the who 2 html snippet (slightly modified)
> from the ftp site
>
> It goes fine manually. But freezes when it goes into ftp
>
>    system("ftp -n members.home.net"); /* The -n is because I can't
> get              it to work without -- but works with -n manually */
>    system("user");
>    system("medievalconquest");
>    system("****"); /* Password would replace **** */
>    system("send c:/mud/public-html/who.html");
>    system("quit");
>

        Unfortunately, you cannot work it like that.

                        *Sighs*

        Okay, first, you should probably tend to use the exec() commands
via a fork, so as to avoid the lockup you noticed, and also to allow the
process to be interruptable - for alot of reasons.

        That out of the way, lets look at the description of the system()
call (from a linux machine in this case);

       system() executes a command specified in string by calling
       /bin/sh -c string, and returns after the command has  been
       completed.   During execution of the command, SIGCHLD will
       be blocked, and SIGINT and SIGQUIT will be ignored

        So, what they're saying is that they'll return when the command is
complete.  That's right, ONLY when the command is complete. Command in
this case meaning whatever you run (not the command of the program you're
running, like get or send, but like 'ftp' or 'finger').  So your program
freezes, happily waiting for the system command to complete.

        Which it won't ever do, considering that it's an interactive
process and you don't have any interactive mechanisms.  It is not a
trivial task to automate interactive processes from within a C program.
It can be done, but again - it's very difficult.

        You need to find a different way to acomplish what you're trying
to do - i recommend just connecting to the ftp port directly, and sending
the correct info via a socket.  Of course, on a seperate fork so as to
allow for the fact that you don't want to halt your mud while your
download runs.

        This is why the original who2html code - which is intended to run
on the same machine that the web info is being hosted on - only moves a
file, and does not fork.

                                                        PjD

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/03/01 PST