Need to download exact copy of text file...little squares replace carriage returns

M

mortgages2005

I need to download a text file from my server. I've tried to use a
program to email it and another to make the browser download the file
with a file save as dialog. The text file has a few charaters and then
some spacing, as many as 120 spaces following by a new line. (line
feed carriage return) I hear unix or linux stores a new line as a line
feed only. After the file is saved to my hard disk through the save
file routine, I should be able to open it up in notepad and not see a
whole bunch of little squares which replaced all the carriage returns.
I need an exact copy of the file as it is correctly saved on the
server. I know it is correct because I'm able to drag it from my FTP
client into my local browser and it opens up in notepad without the
little squares. I can also even right click on the file on my server,
and do view the file, which will transer it over to my computer, open
it in notepad, and there won't be any square boxes replaceing the
carriage returns.

Why is it when I save a file this happens? Is it my browser settings?
I've tried two browsers. They both do the same thing.

Here is the code:

#!/usr/bin/perl

use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);

my $files_location;
my $ID;
my @fileholder;
my $subdirectory=param('subdirectory');
$ID = param('ID') . "du.txt";

$files_location = "/home/mortga20/public_html/$subdirectory/";
#print "Content-type: text/html\n\n";
#print "files_location is " . $files_location;
#exit;
if ($ID eq '') {
print "Content-type: text/html\n\n";
print "You must specify a file to download.";
exit;
}

open(DLFILE, "<$files_location/$ID") || Error('open',
'$files_location/$ID');

print header( -type => 'application/x-download',

-attachment => $ID,

);

print $_ while (read(DLFILE, $_, 1024));

close (DLFILE) || die ("Can't close file!");

open(LOG, ">>/home/mortga20/public_html/$subdirectory/log.txt") || die
("Can't open file!");
print LOG "$ID\n";
close (LOG);

print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder
 
G

Gunnar Hjalmarsson

I hear unix or linux stores a new line as a line
feed only. After the file is saved to my hard disk through the save
file routine, I should be able to open it up in notepad and not see a
whole bunch of little squares which replaced all the carriage returns.

Yes, you see those squares when you view a Unix formated file in Notepad.
I need an exact copy of the file as it is correctly saved on the
server.

But that is contradictory. If you want it to make sense when viewed in
Notepad, then you actually want to convert it to Windows format.

perldoc -f binmode
 
E

Eric Bohlman

(e-mail address removed) wrote in @g14g2000cwa.googlegroups.com:
I need to download a text file from my server. I've tried to use a
program to email it and another to make the browser download the file
with a file save as dialog. The text file has a few charaters and then
some spacing, as many as 120 spaces following by a new line. (line
feed carriage return) I hear unix or linux stores a new line as a line
feed only. After the file is saved to my hard disk through the save
file routine, I should be able to open it up in notepad and not see a
whole bunch of little squares which replaced all the carriage returns.
I need an exact copy of the file as it is correctly saved on the
server. I know it is correct because I'm able to drag it from my FTP
client into my local browser and it opens up in notepad without the
little squares. I can also even right click on the file on my server,
and do view the file, which will transer it over to my computer, open
it in notepad, and there won't be any square boxes replaceing the
carriage returns.

As Gunnar pointed out, your requirements are contradictory. What you're
getting from your FTP server is *not* an "exact copy" of the file; rather
your FTP client and server are translating the line endings (by running
the connection in "ascii" rather than "binary" mode), exactly as your
script would if you used binmode().

Why do you need to maintain an "exact copy" locally in any case? If you
need to modify it locally and then FTP it to the server, the FTP process
will take care of translating the line endings back.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top