[SOLVED] FTP Put a zip file that contains text files in Linux
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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).
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.
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!
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
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:
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?
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.
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
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).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.