FTP in ASCII mode from UNIX to NT

J

jiju

hi,

I can't open up a text file that I FTP'd from UNIX to Windows 2000
even though I set the type to ASCII mode ($ftp->ascii();). I guess it
has to do with carriage return character not encoding correctly on
2000 machine. Is there any work around to fix this problem so I could
open this file up in Notepad?? Need to have it in Notepad to use with
MS Access

thanks,
jju
 
J

James Willmore

I can't open up a text file that I FTP'd from UNIX to Windows 2000
even though I set the type to ASCII mode ($ftp->ascii();). I guess
it has to do with carriage return character not encoding correctly
on 2000 machine. Is there any work around to fix this problem so I
could open this file up in Notepad?? Need to have it in Notepad to
use with MS Access

I'm not sure if this will help you or not. I had a script that took a
file and sent it from a Windows machine to our S/390. When we
upgraded the Windows machine from 98 to 2000, the line ending
characters were fouled.

Now, the usual approach is to either use tr or a regex to change the
line ending characters to what is needed. Guess what? It didn't
work. The issue always arose AFTER the file was created on the file
system. The actual scalar value involved was correct BEFORE writing
to file.

So, I decided that, since the file system didn't want to play nice,
I'll avoid writing the file to it. You may want to write the file to
an IO::Scalar object first, do any line ending substitution on the
IO::Scalar object, then write the IO::Scalar object to file.
Not elegant or efficent, but it did the trick for me.

HOWEVER, I know the size of the file is small (always less than a few
kilobytes), so memory is not really an issue. Depending on the size
of the file you're dealing with, you may have to take a different
approach.

HTH

Jim
 
S

Stefan

jiju said:
hi,

I can't open up a text file that I FTP'd from UNIX to Windows 2000
even though I set the type to ASCII mode ($ftp->ascii();). I guess it
has to do with carriage return character not encoding correctly on
2000 machine. Is there any work around to fix this problem so I could
open this file up in Notepad?? Need to have it in Notepad to use with
MS Access

thanks,
jju


Windows text files use CR (= \r) + LF (= \n) as an end-of-line marker, while
Unix just use LF (= \n). So, before you FTP over a text file, change the
end-of-line marker and store everything in a temporary file. Then transfer
the tmp-file as if it was the source file: $ftp->put(tmp-file, source-file).
Make sure to use binary mode (or at least test ascii mode).

FreeBSD has the commands unix2dos and dos2unix which describe what you're
seeing. Perhaps your Unix flavour has it too.

Bye,
Stefan
 
T

Tad McClellan

jiju said:
someone else also gave me a tip. `perl -p -i -e 's/\\n/\\r\\n/'
$filename` to replace the newlines with carriage returns in DOS.


That code does *not* replace the newlines with carriage returns.
 

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

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,216
Latest member
topweb3twitterchannels

Latest Threads

Top