Read/write fifo - ftp

This is a discussion on Read/write fifo - ftp within the C Programming forums, part of the General Programming Boards category; Hi Gang, I need to be able to read a mainframe file from special device /dev/vme and ftp the file ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    1

    Question Read/write fifo - ftp

    Hi Gang,
    I need to be able to read a mainframe file from special device /dev/vme and ftp the file using a fifo file to a remote host.
    The reason behind this is because the file is Ebcdic binary which needs to be sent unchanged.
    I know Unix but am not a C programmer so I've had to 'make it up' as I go along - a C program has to be used to call the special function VMESETMODE which tells is not to convert from Ebcdic to Ascii. I have spent many an hour cobbling together the code below - it compiles and runs but the resultant file on the remote host is empty.
    If anyone can show me where I am going wrong with the C program I will be very grateful.

    Unix does ;

    /etc/mknod myfifofile
    ftp remote-host
    put "| cftp /de/vme/MYFILE" remote-file

    C program 'cftp' contains

    £include <stdlib.h>
    £include <stdio.h>
    £include <limits.h>
    £include <vmeio.h>
    £include <fcntl.h>

    £include <sys/types.h>
    £include <sys/stat.h>

    £include <unistd.h>

    void main(argc,argv)
    int argc;
    char *argv[];
    {
    char buff[LINE_MAX]; /* Input buffer. */

    int c, in_file, out_file, i_nul = 0;

    if ( ! ( argc > 1 ) )
    {
    fprintf ( stderr, "Error : Filename not specified\n" );
    exit(1);
    }

    if ( ( in_file = open ( argv[1], O_RDONLY ) ) < 0 )
    {
    fprintf ( stderr, "Error (%i) : Unable to open %s\n", in_file, argv[1] )
    ;
    exit(1);
    }

    if ( ioctl ( in_file, VMESETMODE, &i_nul ) < 0 )
    {
    fprintf ( stderr, "Error : Could not VMESETMODE on %s\n", argv[1] );
    exit(1);
    }

    while ((c = read (in_file, buff, LINE_MAX)) >0 )
    {
    if( printf( stdout, buff, c ) != c )
    {
    fprintf ( stderr, "Error : Writing to stdout\n" );
    exit(1);
    }
    }

    if ( c < 0 )
    {
    fprintf ( stderr, "Error : Reading from %s\n", argv[1] );
    exit(1);
    }

    close(in_file); /* No error checking */
    }

    Yours hopelessly out of depth,

    Al

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    1. void main(argc,argv)
    main returns an int

    2. This style of function declaration died about 10 years ago.
    > void main(argc,argv)
    > int argc;
    > char *argv[];

    3. Use write, not printf - write does not interpret the data being written to the file, printf can (and does).
    > if( printf( stdout, buff, c ) != c )
    This call is wrong in several ways, its no surprise that the file is empty.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simultaneously waiting for data on FIFO and UDP using select call
    By yogesh3073 in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-05-2007, 08:53 AM
  2. working with FIFO files
    By icebabe in forum C Programming
    Replies: 6
    Last Post: 05-06-2006, 11:35 AM
  3. help! fifo read problem
    By judoman in forum C Programming
    Replies: 1
    Last Post: 08-16-2004, 09:19 AM
  4. FTP and Ident Server :: Winsock
    By kuphryn in forum Networking/Device Communication
    Replies: 2
    Last Post: 03-13-2004, 07:16 PM
  5. FTP Server :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 10-03-2002, 07:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21