File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Security and the fly likes Remove ^M character in text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Security
Bookmark "Remove ^M character in text file" Watch "Remove ^M character in text file" New topic
Author

Remove ^M character in text file

Sivaraman Lakshmanan
Ranch Hand

Joined: Aug 02, 2003
Posts: 231
Hi All,
I sftp (secure FTP) some text files from unix box to another unix box using the JSCH API. When the same file is FTPed I don't see the ^M character but the SFTped file has a ^M characters at the end of each line of the file. I cannot use any utility to remove the ^M characters. Is there any settings that I can do in the Unix box to solve this or is there any settings in the JSCH API to solve this.

Any help on this is very much appreciated.


Regards,
Sivaraman.L
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
FTP has a setting to transfer files in binary mode instead of ASCII mode; that should prevent any changes from happening.


Ping & DNS - updated with new look and Ping home screen widget
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4637
    
    5

Perhaps Ulf has it backwards? If you send it binary, it is send as is. If yo used it as text, it allows line conversions.

Many SFTP implementations don't have modes like ftp did. And since OP talks about using an API, what is supported depends on the API.

If you can't use something nice, like dos2unix, you can always just chop off the ^M at the end of lines after you use a readline() to get the string.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Remove ^M character in text file
 
Similar Threads
How to to recognize new line character?.
Reading logs from Unix server
Finding new line character or special characters in txt file ?
Invoking unix shell commands from java.
Different character sets on Unix/Windows? Whats happening?