CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2011
    Posts
    7

    Question 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.

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: FTP Put a zip file that contains text files in Linux

    A zip file is a binary file and hence, as you have found out, needs to be transferred as a binary file. The contents of the zip file are not relevant, in their original form the files you have added could be all binary, all text or a combination of text and binary but once added to the zip they are part of a binary file.

    How are you zipping the files up and how are you extracting the files from the transferred zip file and where does Java come into this problem?
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Nov 2006
    Location
    Barcelona - Catalonia
    Posts
    364

    Re: FTP Put a zip file that contains text files in Linux

    Hi,
    I think your problem has nothing to do with FTP transfer mode (which as keang told you MUST be binary, no matter what type of data are inside ZIP).

    What do you refer where you said: "distorted and unreadable"? You problem could be the way each operating system treats end of line.
    Windows uses two characters to insert and 'end of line' (\r\n), however linux just use one character (\n).
    Depending on the editor you are using to handle these files the behaviour might change. E.g. under vi editor the end of line is usually shown as a character "^M" when you edit a file that has been created by Windows.
    To solve that, just type:
    dos2unix fileIn > fileOut
    where fileIn is the file in Windows format and fileOut is a new file with Unix/Linux format. Well, it is not really a file format, it's just the way Linux o Windows treats end of line.

    If you are not using Linux, but a Unix based operating system, like AIX. It probably don't have that command. In this case use this one, which removes all characters '\r' in file:
    tr -d '\r' < fileIn > fileOut
    BTW, at what point is your question related to Java? xD

    Hope this helps.

    Regards.
    Last edited by AlbertGM; September 13th, 2011 at 07:02 AM.
    Please, correct me. I'm just learning.... and sorry for my english :-)

  4. #4
    Join Date
    Sep 2011
    Posts
    7

    Re: FTP Put a zip file that contains text files in Linux

    Thanks so much. You were both 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 ^.^

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured