SCP / SFTP / FTP file transfer ended with ^M (Control-M) characters

If you are like me, trying to transfer some ASCII files to a Linux / Unix machine.
But ended up the file being added modified with ^M characters at the end of each line as below:

- to get ^M type CTRL+V followed by CTRL+M
- UNIX style file (LF terminated)

- DOS style file (CRLF terminated)

If you are using SFTP or SCP to do the job, then you are out of your luck to have it settle on the fly.
There are some suggestion to use "sed" to remove those characters as below, but this adds extra jobs, and even worse if you are transferring numerous files at numerous directories.

If your destination Linux / Unix machine has the FTP service enabled, then you can probably just choose FTP client like Filezilla to transfer in ASCII mode for those files (Make sure you are using FTP protocol instead of SFTP or SCP). Or you may just choose to use "Automatic" file type transfer, since default setting will recognize most of the file type that

FTP supports switching between Binary and ASCII transfer mode and converting data on the fly but SFTP / SCP does not support that feature and it always transfers files unchanged

Common FTP client:

No comments: