LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-12-2011, 10:38 PM   #1
kazeopeia
LQ Newbie
 
Registered: Sep 2011
Posts: 10

Rep: Reputation: Disabled
FTP Put a zip file that contains text files in Linux


Hi all,

I am transferring a file from a linux pc going to a windows ftp server using "ftp put". My file is a zip file that includes .txt files inside it.

Here is what's happening when I transfered this file :
1. I used ftp put for transferring and found that my transferred zip file was corrupted and couldn't be opened on the ftp server.
2. I found the solution for this on the internet. I needed to use 'binary' to make it right.
3. I transferred again using binary and then ftp put the zip file onto the other end. Yes, it worked. My zip file wasn't corrupted anymore and I could already opened it on the ftp server. But the problem remains on the .txt files inside it. Converting the file into binary made my .txt files to be distorted and unreadable. I read from the internet that .txt files need to use Ascii instead of Binary to be readable, but if I use ascii it would cause my zip file to be corrupted again.

Is there any way to solve this? I need to successfully transfer a zip file that contains .txt files using ftp put.

Please help.
Thank you very much for any quick and kind response.
 
Old 09-12-2011, 10:55 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
What that boils down to is that 'zip' is a binary format, but txt files in *nix have a line ending '\n', whereas MS uses '\r\n'.
I believe(?) notepad (or notepad++) may be able to handle (open) them, then you can 'save as...'.

HTH

FYI, on *nix there is a util dos2unix (sometimes dostounix) that can cvt MS or MAC =>*nix.
You can also use unix2dos http://linux.die.net/man/1/unix2dos to cvt *nix => MS or MAC; I'd suggest doing this on Linux before ftp to MS.
 
1 members found this post helpful.
Old 09-12-2011, 11:52 PM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
As you don't describe the exact corruption, chrism01's reply makes sense. You can test by opening the 'corrupted' files in wordpad and it should display properly. Notepad will show its limitations and display one long line with little squares wher the newlines are.

Another editor that can do the job in Windows is PFE (programmers file editor, very old and no longer maintained but still my favorite)

If you use Ubuntu, the utilities are called todos and fromdos (and are not installed by default).
 
Old 09-13-2011, 12:59 AM   #4
kazeopeia
LQ Newbie
 
Registered: Sep 2011
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thanks to both of you.

OK so there is a conflict upon creating text files on Linux and MS. I tried what you said, before I do the ftp transfer, I wrote this

unix2dos mytext.txt

and it resulted with bash: unix2dos: command not found

I also tried whereis unix2dos command but it just gave me this result
unix2dos:

what should I do? I know you told me that they aren't installed by default but how can I get this command to work?

THANKS!
 
Old 09-13-2011, 01:24 AM   #5
dudeman41465
Member
 
Registered: Jun 2005
Location: Kentucky
Distribution: Debian
Posts: 794

Rep: Reputation: 56
Maybe I'm missing something, but I'm not understanding why a file transfer would have any effect on the contents of a file. Doesn't it just transfer the files bit by bit exactly as they are? I've been transferring files to and from my server(Runs Debian Linux) using FTP and multiple operating systems for years and never had an issue like this.

What FTP client are you using, just the command line tool "ftp"? Also if the binary executable for "unix2dos" is not installed in your $PATH, you may have to cd into the directory where it is located and execute it directly with:

Code:
./unix2dos mytext.txt

Last edited by dudeman41465; 09-13-2011 at 01:27 AM.
 
Old 09-13-2011, 01:34 AM   #6
kazeopeia
LQ Newbie
 
Registered: Sep 2011
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thanks dudeman41465,

Yes, I am executing FTP commands just on the command line.
If I would have to use "unix2dos" command, How would I know where it is located?

I tried "whereis unix2dos" command but it just gave me this result:
unix2dos:
 
Old 09-13-2011, 02:13 AM   #7
kazeopeia
LQ Newbie
 
Registered: Sep 2011
Posts: 10

Original Poster
Rep: Reputation: Disabled
Hi all,

I've read from this site http://yourlinuxguy.com/?p=232 that I can no longer use "unix2dos" command.. but instead I can use the "recode" command..

And so, following chrism01's suggestion to convert first before ftp to MS I did the following :

Code:
 
recode latin1..dos /complete_path_of_my_zip_file/myzip/mytext.txt
ftp 10.11.*.*
<i entered username and password and had successfully logged in>
lcd /complete_path_of_my_zip_file
binary
put myzip.zip
Still, the problem persist. I was able to open myzip.zip on the ftp server but when I opened mytext.txt the file contents are still distorted and has little boxes in it. However, I was able to open it successfully using wordpad. But that's not what I actually want and need. I need to open the file as text file and not on wordpad.

What am I doing wrong? I really, really need your help. Please.
Thanks!
 
Old 09-13-2011, 02:40 AM   #8
resolv_25
Member
 
Registered: Aug 2011
Location: Croatia
Distribution: Debian 10/Ubuntu 20.04
Posts: 64

Rep: Reputation: 15
I had same problem, txt created on linux is not properly read by windows.
Eventually, on linux open the txt file with wine->wordpad, save,
then is properly open on windows.

Otherwise, document saved with gedit, open office, gphpedit, nano is not correctly open on windows.

Also, if using some script as PHP for creating txt file, it can be defined that line ending is with \r\n
instead of native linux \n
 
1 members found this post helpful.
Old 09-13-2011, 07:19 AM   #9
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
Which distro are you using?
 
Old 09-13-2011, 10:40 AM   #10
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
you can try running something like
Code:
sed 's/$'"/`echo \\\r`/" lf-in.txt > crlf-out.txt
but that didnt work for me.

the underlying problem is the pkzip program that is available on my aix machine doesnt deal well with windows cr-lf's (i never found a solution).

how are you zipping up the files ?
 
Old 09-13-2011, 11:29 AM   #11
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
Quote:
Originally Posted by kazeopeia View Post
Hi all,

I've read from this site http://yourlinuxguy.com/?p=232 that I can no longer use "unix2dos" command.. but instead I can use the "recode" command..

And so, following chrism01's suggestion to convert first before ftp to MS I did the following :

Code:
 
recode latin1..dos /complete_path_of_my_zip_file/myzip/mytext.txt
ftp 10.11.*.*
<i entered username and password and had successfully logged in>
lcd /complete_path_of_my_zip_file
binary
put myzip.zip
Still, the problem persist. I was able to open myzip.zip on the ftp server but when I opened mytext.txt the file contents are still distorted and has little boxes in it. However, I was able to open it successfully using wordpad. But that's not what I actually want and need. I need to open the file as text file and not on wordpad.

What am I doing wrong? I really, really need your help. Please.
Thanks!
The problem here is that you:

1) Recoded the text file
2) Put the zip file

And the obvious missed step is that after you recode the text file, it needs to be zipped. You re-sent the old zip file that had the old, unrecoded text files inside. So the process you're looking for is:

1) Recode
2) Zip
3) FTP put

And here's an alternative, if the text files aren't large enough that zipping is not entirely necessary:

1) FTP mput in ASCII mode.
 
Old 09-13-2011, 11:32 AM   #12
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
Actually, I take part of that back... it looks like you tried to recode the file in the zip archive. How can you change CRLF characters if the file is zipped?
 
Old 09-13-2011, 11:49 AM   #13
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,696

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
What text editor/program are you using to create the file in linux?
Just for completeness what linux distribution/version are you running?
Did you zip the file after you used the recode utility?

Quote:
I was able to open it successfully using wordpad. But that's not what I actually want and need. I need to open the file as text file and not on wordpad.
Please elaborate. What application do you want to use to open the file? Wordpad is able to read/write ASCII text files. It will also automatically convert from unix to DOS when it opens the file.

Last edited by michaelk; 09-13-2011 at 11:52 AM.
 
Old 09-13-2011, 12:07 PM   #14
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

Rep: Reputation: Disabled
The unix2dos program you're looking for is in the dos2unix package (at least it is on all Debian releases). I don't know what distro you're using so I can't be more specific.
ciao,
jdk
 
Old 09-13-2011, 10:03 PM   #15
kazeopeia
LQ Newbie
 
Registered: Sep 2011
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thanks so much. You were all right.

FTP Transfer of zip file from linux to windows server doesn't affect the contents of the zip file. I am generating my text files dynamically through java code and what actually happens is that text files transferred to windows ftp server uses the line ending \r\n instead of just plain newline ( \n ).

I just changed my line endings into \r\n to make it work and be readable when opened even on notepad ('coz I am really required to open the files using notepad).

Thank you so much for all your help ^.^
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux zip program's -d -tt option deletes all files from zip archive Arun Gupta Linux - Software 4 04-27-2011 07:06 PM
Read a text file and ftp files using bash w/out leaving the ftp prompt dj_tyr Linux - Newbie 6 10-12-2009 06:46 PM
Archive manager not recognising ZIP files - suggests it's a text file. AnanthaP Ubuntu 4 12-27-2007 07:10 AM
need a perlscript to read from a text file and transfer files via ftp cccc Linux - Networking 2 02-21-2004 06:18 PM
Where do I put my text files rewtem General 4 03-27-2003 08:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration