• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Remove ^M character in text file

 
Sivaraman Lakshmanan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FTP has a setting to transfer files in binary mode instead of ASCII mode; that should prevent any changes from happening.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic