boat73 has asked for the wisdom of the Perl Monks concerning the following question:

Hello wise ones. I have a script that gets a file off of a mainframe. I then import the file into MSSQL using a dts package. If I run the ftp manually using dos the file imports fine. If I use the perl code I error out when I try to do the import. When I run the FTP in dos I run through all the same commands and if I open the csv in excel it looks fine. The MSSQL error sais it can't find a CR/LF in the first 8k. Any help is appreciated.
my $host1='myhost'; my $user1="user"; my $pw1="pwd"; my $path = 'MY.FILE.NAME'; my $dataFile="MY.FILE.NAME\.csv"; my $mffile = '\'MY.FILE.NAME\''; #### Pull file off mainframe #### $ftp=Net::FTP->new($host1, Debug => 1); $ftp->login($user1,$pw1) or die "could not login to $host1"; $ftp->cwd($path) or die "could not cwd $path"; # change to incoming + directory $ftp->get($mffile) or die "could not get $file";

Replies are listed 'Best First'.
Re: Net::FTP seems to be corrupting my file
by jettero (Monsignor) on Mar 16, 2007 at 18:37 UTC

    At a guess, it is indeed corrupting your file. The bug is known. Choose $ftp->binary, which solves the problem. It shouldn't be necessary to call it, but for today, it'll help a lot.

    The tickets for the package show the bug listed in several different ways — probably because people don't read tickets before posting bugs? Basically, it's removing the last character from each line.

    -Paul

      Thanks for the response. I did call binary after which the CSV could not be opened with excel.
Re: Net::FTP seems to be corrupting my file
by roboticus (Chancellor) on Mar 19, 2007 at 01:50 UTC
    boat73:

    I've encountered the same thing. At my facility, it appears that the command-line FTP is in ASCII mode, so when I download a file, it automatically converts from EBCDIC to ASCII. IIRC, Net::FTP defaults to binary mode, in which case you'll get an EBCDIC file, which is a bit of a nuisance. 8^)

    --roboticus

      I thought it might be something like that. i tried calling $ftp->ascii, but that didn't seem to fix the problem. Has anyone done ftp using NET:CMD? If so i greatly appreciate some sample code. Thanks in advance.
        boat73:

        You might then try the rhelp and or rstatus commands to get a list of the commands that your FTP server supports and look for clues. On our mainframe, for example:

        ftp> rhelp 214-The server-FTP commands are: 214-ABOR,*ACCT,*ALLO, APPE, CDUP, CWD, DELE, FEAT, HELP, LANG, LIST, +MDTM, MKD 214-MODE, NLST, NOOP, OPTS, PASS, PASV, PORT, PWD, QUIT, REIN, REST, +RETR, RMD 214-RNFR, RNTO, SITE, SIZE, *SMNT, SYST, STAT, STOR, STOU, STRU, TYPE, + USER 214-ADAT, AUTH, CCC, PBSZ, PROT, EPSV, EPRT 214-The commands preceded by '*' are not implemented 214-The data representation type may be ASCII, EBCDIC or IMAGE, or may + be 214-one of the following Double Byte Character Sets: *** SNIP *** 214-For information about a particular command, type 214 HELP SERVER command or QUOTE HELP command
        Looking at the list of commands available, I dig through a few until I find:
        ftp> rhelp type 214-TYPE {representation-type} {format}: the default type is ASCII. 214-The implemented data types are ASCII(TYPE A <N>), EBCDIC (TYPE E < +N>), 214-IMAGE (TYPE I), DBCS (TYPE B <options>), and UNICODE (TYPE U 2 <B +| L>). 214 The local byte size is 8.
        (The output of rstatus is too long and boring to bother including here, but may have usefulclues for you as well.)

        Anyway, if your server implements some particular command, then you can use the quote method of Net::FTP to send a particular command string to the server to get what you want.

        I hope this is of some use to you...

        roboticus