my dog learned polymorphism*
The moose likes Ant, Maven and Other Build Tools and the fly likes ANT FTP download new line problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "ANT FTP download new line problem." Watch "ANT FTP download new line problem." New topic
Author

ANT FTP download new line problem.

hasan khan
Ranch Hand

Joined: Aug 04, 2003
Posts: 222

while downloading some class files and jsp files from remote server i am getting some special character at the end of each line and i can see it this in text editor for jsp files and java decompiler is unable to open my class files. what to do to remove those unwanted characters.


SCJP, SCWCD
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

See if fixcrlf task helps.


[My Blog] [JavaRanch Journal]
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

Did you use the ftp task to get the files? Did you remember to set the binary mode attribute?

Also what OS are you transferring files from and to. If you do not have binary mode set, when files are transferred from Linux to Windows, a CR char is added before every LF char. And in the other direction, every CR-LF combo is changed to only LF.


JBoss In Action
hasan khan
Ranch Hand

Joined: Aug 04, 2003
Posts: 222

FixCRLF helped me to some extend for JSP files, but didnt worked for .class files.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

You need to FTP class files with the binary option set. Using FixCrLf can further corrupt binary files.
[ July 17, 2008: Message edited by: Peter Johnson ]
hasan khan
Ranch Hand

Joined: Aug 04, 2003
Posts: 222

so please suggest any solution for downloading any binary file from UNIX to windows using ANT FTP.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

Please post the ant task you are using to download the files from FTP. Based on the FTP task documentation, the binary mode is set to "yes" by default.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

Finally! I now know the direction you are transferring files. And with FTP the direction of transfer is critical.

Your original post has me confused. You claim that both Java source files (text) and class files (binary) were corrupted during the FTP. That is not possible from a single FTP task. Let me explain.

1) If you ftp as binary, then text files keep the CR-LF line ending characters. And in an editor on Linux you will see funny characters at the end of each line. But binary files are transferred as-is, meaning the class files could not have been corrupted.

2) If you ftp as text, the the Java source files will transfer correctly, with CR-LF chars being changed to LF. No funny characters at end-of-line in the editor. But that same CR-LF to LF conversion can corrupt binary files, meaning your class files are now corrupt.

Therefore, either the source files of the class files get corrupted in a single ftp transfer. But not both.

FixCrLf can further corrupt binary files. Consider a binary file on Windows with some LF chars and some CR-LF combinations. After a text mode ftp to Linux, all of the CR-LF combos will be turned to LF. Running FixCrLf then takes all LF chars and converts them to CR-LF, leaving no free-standing LF chars (as there were in the original binary). So the binary is still screwed up. In short, after a text-mode FTP, binary files are hopelessly corrupt and cannot be fixed. The only solution is to re-transfer the file in binary mode.

(Sorry, I was a teacher in a former life and occasionally that teacher repossesses my body...)
hasan khan
Ranch Hand

Joined: Aug 04, 2003
Posts: 222

i have modified org.apache.commons.net.ftp.FTPClient.setFileType(int fileType) by adding line this in the beginning.


and it is working fine for me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ANT FTP download new line problem.