We wrote our own “ftp server” in C. Basically, you start up the standard ftp
client program from your C program, connected via a pipe. You then send the
ftp commands down the pipe, set alarm() for the amount of time that you are
willing to wait, and go to sleep. If the alarm goes off, you kill the client
and try again, or declair failure. If the ftp client finishes and exits, you
then do something like a checksum on the receiving side of the ftp transfer
to ensure that things went as planned.
We have another queueing task on the “other side” of our C program; it
queues up requests so that other tasks can ask for a transfer and then go
back to work. When the C program finishes a request, either successfully or
not, it then sends a message back to the requesting task informing it of
status.
The procedure for starting up the ftp client uses a “timed popen”, which is
a set of C routines documented in one of the books by Stevens.
We have also used Expect and Perl to do this sort of thing, both with great
success. Which one you use depends on your religious persuasion.
“Philippe Frossard” <philippe.frossard@free.fr> wrote in message
news:3A1D20E3.41D5F97F@free.fr…
There is not another solution with C program ?
Richard R. Kramer a écrit:
May I suggest you try “expect”; I had no trouble compiling it with
Watcom 10.6. Expect is very good with respect to handling errors that
ocurr with ftp, telnet, etc. There are two books (in English) that I
have used - both are from O’Reilly - one is “Exploring Expect” and the
other is “TCL/TK in a Nutshell” (Expect is built using TCL).
Richard
Philippe Frossard wrote:
I would like to send some files by FTP …
I have make a script like this (with a .netrc)
#!/bin/sh
export HOME=/root # Mark environment variables for
export
typeset -i iReturn # Define exit code
iReturn=-1 # Set exit code
if test $# -eq 1 # The number of positional
parameters
then
if test -d /ram/as400/tosend # File is a directory
then
cd /ram/as400/tosend # Change working directory
if test -f $1 # File is a regular file
then
Ftp to AS400
ftp as400 << THE_END
cd olcftp
put $1
bye
THE_END
End of input command
iReturn=0 # Set exit code
fi
fi
fi
exit $iReturn # Cause the shell to exit
– This script is call by C program like this …
But, when the FTP crash, I don’t have any informations …
What can I do ? (Time out of FTP ?)
/* Make a system command /
strcpy(ucBufferCom, "/bin/ftpbatch ");
strcat(ucBufferCom, dReceiveInfo->d_name);
strcat(ucBufferCom, “\n”);
/ Execute a system command /
if ((iReturn = system(ucBufferCom)) != -1)
{
if (WEXITSTATUS(iReturn) != 0xFF)
{
/ Make a system command /
strcpy(ucBufferCom, "rm ");
strcat(ucBufferCom, ucBufferSrc);
strcat(ucBufferCom, “\n”);
/ Execute a system command */
system(ucBufferCom);
}
}
–
Philippe Frossard : 74890 FESSY (FRANCE)
Courrier Electronique : mailto:> <philippe.frossard@free.fr>
Site Internet : > http://philippe.frossard.free.fr
–
Philippe Frossard : 74890 FESSY (FRANCE)
Courrier Electronique : mailto:> <philippe.frossard@free.fr>
Site Internet : > http://philippe.frossard.free.fr