Send file by FTP ...

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

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

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

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.

  • Kevin

“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

Kevin Miller <kevin.miller@transcore.com> wrote:

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.

The problem with popen() for an ftp is that ftp will do an open("/dev/tty")
to prompt for a password if it needs one to login with. That will not
go to the process trying to control it with popen. ftp will look in
a local .netrc file for passwords and userids – so this may not be
a critical failure. But, if you want to control ftp this way – say
you want to put a GUI front end on it – you are better off using a
pseudo-tty pair than popen(). [Advanced Programming in the Unix
Environment
by W. Richard Stevens has a good chapter pseudo terminals.]

-David

QNX Training Services
dagibbs@qnx.com

David Gibbs <dagibbs@qnx.com> wrote:
: Kevin Miller <kevin.miller@transcore.com> wrote:
:> 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.

: The problem with popen() for an ftp is that ftp will do an open("/dev/tty")
: to prompt for a password if it needs one to login with. That will not
: go to the process trying to control it with popen. ftp will look in
: a local .netrc file for passwords and userids – so this may not be
: a critical failure. But, if you want to control ftp this way – say
: you want to put a GUI front end on it – you are better off using a
: pseudo-tty pair than popen(). [Advanced Programming in the Unix
: Environment
by W. Richard Stevens has a good chapter pseudo terminals.]

In addition to Dave’s comment, you can also start ftp with ‘-n’.
Meaning do not attempt to auto-login. ftp does not do explicitely
“/dev/pty” but rather it is call when entering the passwd, probably
by getpass() or something similar to turn off echo’ing. After
doing ‘-n’ you will have to send a “USER %\r\n” “PASS %s\r\n”
your self.

There is suppose to be a libftp.a somewhere on usr/free.


au revoir, alain

Aussi haut que l’on soit assis, on n’est toujours assis que sur son cul !!!

“Alain Magloire” <alain@qnx.com> wrote in message
news:91lb7a$8fo$1@nntp.qnx.com

David Gibbs <> dagibbs@qnx.com> > wrote:
: Kevin Miller <> kevin.miller@transcore.com> > wrote:
:> 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.

: The problem with popen() for an ftp is that ftp will do an
open("/dev/tty")
: to prompt for a password if it needs one to login with. That will not
: go to the process trying to control it with popen. ftp will look in
: a local .netrc file for passwords and userids – so this may not be
: a critical failure. But, if you want to control ftp this way – say
: you want to put a GUI front end on it – you are better off using a
: pseudo-tty pair than popen(). [Advanced Programming in the Unix
: Environment
by W. Richard Stevens has a good chapter pseudo terminals.]

In addition to Dave’s comment, you can also start ftp with ‘-n’.
Meaning do not attempt to auto-login. ftp does not do explicitely
“/dev/pty” but rather it is call when entering the passwd, probably
by getpass() or something similar to turn off echo’ing. After
doing ‘-n’ you will have to send a “USER %\r\n” “PASS %s\r\n”
your self.

There is suppose to be a libftp.a somewhere on usr/free.


au revoir, alain

Aussi haut que l’on soit assis, on n’est toujours assis que sur son cul
!!!

ftp -n is exactly the technique we use. When using telnet under program
control, we use the pty approach.