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

Hi I am really despaired, I have no idea what to do anymore. I need to download a plain Textfile size ~20 mb from a TSO machine to my Windows 2000 system daily. I use the newest Activestate Perl distribution (5.8) I use the following code:
use strict; use Net::FTP; my $hostname = 'localhost'; my $username = 'slip'; my $password = 'knot'; my $file = 'version.txt'; my ($ftp, $code, $msg); $ftp = Net::FTP->new($hostname); if($@) { print "Error connecting to $hostname: $@"; exit; } $ftp->login($username,$password); $code = $ftp->code; unless ($code == 230) { $msg = $ftp->message; print "Error logging in: $code $msg"; exit; } $ftp->ascii(); $ftp->get($file); $code = $ftp->code; unless ($code == 150 || $code == 226 || $code == 250) { $msg = $ftp->message; print "Error getting $file: $code $msg"; exit; } $ftp->quit;
______________________________________________________ OK now the weird thing and I have no idea what to do anymore. The File doesn´t seem to have a end of line. Neither Notepad nor Perl "can see" the End of Line. If I get the File manually via DOS command box and the ftp command the file does have a normal End of Line. If I open the file downloaded with the Perl code with a Texteditor like Ultraedit, Ultraedit thinks that this is a Hex File. Changing to "normal" mode the End of Line exists. So I think the Problem is with Net::FTP it gets the file correctly but doesnt convert the End Of Line correctly to ASCII. Question: Is there any way to fix this Problem, is it a problem in the Net::FTP or what can I do to get the File correctly??? Thanx in advance Ausby

Replies are listed 'Best First'.
Re: Serious Problem with Net::FTP and TSO End of Line "Missing"?!
by Limbic~Region (Chancellor) on Feb 23, 2003 at 20:05 UTC
    Greetings,
    I doubt that this is a bug in Net::FTP, though stranger things have happened. I would suggest taking a look at this neat little script from CPAN.

    Here is its description:

    With this script you can check if a text file is of a specific type and convert it to a different type. Special feature is the ability of fixing files that were broken by wrong ftp upload and download mode (ascii/bin). Supported file types are dos, mac, unix and broken. It also runs under DOS.

    This may get you started in the right direction and is obviously not a permanent solution.

    Hope this helps, cheers, and happy hacking - L~R

Re: Serious Problem with Net::FTP and TSO End of Line "Missing"?!
by pg (Canon) on Feb 23, 2003 at 20:31 UTC
    I am not quite sure whether your TSO stands for the same TSO I know. My TSO is related to IBM mainframe. If that's the case, you may want to look into the ebcdic function of Net::FTP.

    But even between UNIX and DOS, Net::FTP does not handle new lines as one might expected. That's not really a bug, becaue FTP protocol does require the translation, but it is byte by byte, and does not take care of whether your newline is \r, \r\n, or \n, etc.

    Update:

    The translation FTP taken care of for you, is the translation between schemas, but not platform specific things. They (IETF) consider it as beyond the scope of FTP.
      Yes you are correct, it is related to IBM Mainframe, I see your point but what can I do to correct the file then?
Re: Serious Problem with Net::FTP and TSO End of Line "Missing"?!
by tachyon (Chancellor) on Feb 24, 2003 at 13:03 UTC

    As I understand it IBM mainframes use EBCDIC rather than ASCII encoding.

    I suggest the easiest solution is to download the file as binary and then use Convert::EBCDIC to tranform it from EBCDIC to ASCII.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print