Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm getting pretty sick of how WinSCP screws up line breaks.

this is line 1
this is line 2

Gets turned into

this is line 1

this is line 2

I could just use FileZilla for FTP and Putty for SCP (I think putty can handle that) but, that's rather annoying. How can I mitigate this problem?

share|improve this question
1  
You can go into settings and have it use binary instead of automatic. Also if your using an external editor (like i am) be sure it doesnt mess around with it either. Mine has never given me a problem (i use programmers notepad aka pnotepad) –  acidzombie24 Dec 30 '10 at 5:34

4 Answers 4

I'd say that the comment left by acidzombie24 is the best advice. Personally I haven't come across a better FTP program than WinSCP. I recommend you change your settings to transfer using Binary, and use an editor like NP++ rather than the in-house editor.

Here are a few screenshots:

Binary Transfer

Editor

share|improve this answer
    
Adding to Merlin's answer, I fixed this by changing the Transfer preferences from Binary to Automatic. –  desbest Sep 14 '13 at 17:57
    
additionally you need to ensure that "text" mode is not forced on your external editor. Go to Editors, click your editor, click edit... then ensure "Force text transfer mode" is unchecked –  Vigrond Jun 21 '14 at 23:16

Redacted version of WinSCP FAQ Why are text file line breaks wrong after the file is transferred or edited?

See particularly its Known Issues section.


After transferring or editing a file, it may happen that line breaks are wrong, what may manifest as:

  • Line breaks are lost. It seems like if a whole file content is on a single line.
  • Line breaks are duplicated. It seems like there's additional empty line between every line.
  • There's strange symbol/character at the end of every line.

Text File Formats

Different platforms (operating systems) use a different format of text files. The most common formats are Unix and Windows format. A primary difference is that different character or sequence of characters is used to signify an end of a line. On Unix, it's LF character (\n, 0A or 10 in decimal). On Windows, it's a sequence of two characters, CR and LF (\r + \n, 0D + 0A or 13 + 10 in decimal).

While many applications and systems nowadays can work with both formats, some require a specific format. When presenting a file in an another format, they fail to display it correctly, as described above.

Text/ASCII Transfer Mode

For this reason, file transfer clients and servers support text/ASCII transfer mode. When transferring a file in this mode, the file gets (ideally) converted from a format native to a source system, to a format native to a target system. For example, when uploading a text file using text mode from Windows to Unix system, the file line endings get converted from CR+LF to LF.

WinSCP by default uses binary transfer mode for all files. Learn how to configure it to use text/ASCII transfer mode. You may also need to configure correct server-side text file format.

On the contrary, when you want to force WinSCP to use a binary mode, even when editing files in a text editor, you have to use an external text editor (WinSCP internal editor does not support Unix file format) and configure WinSCP not to force text mode for edited files. Also make sure your external text editor saves the file in the format you need (Most text editors nowadays support different text file formats, not just a format native to the platform the editor runs on).

Known Issues with Transfer Mode

  • Pure-FTPd FTP server: When downloading a file with Windows line-endings (CR+LF) in a text/ASCII mode, the server replaces LF with CR+LF, resulting in an incorrect CR+CR+LF. When opening such file in an Internal editor of WinSCP, the editor interprets the sequence as two line endings (CR and CR+LF) resulting in a blank line after each and every content line. When the file is saved, the internal editor saves two Windows line endings CR+LF and CR+LF. On upload they get converted to two LF’s. A workaround is to use an external editor and make sure WinSCP does not force text mode for edited files.

Debugging Text File Conversion

If enabling (or disabling) text/ASCII transfer mode does not help with the problem and your transferred/edited file is still perceived incorrectly by the target system, you need to find out in what step the file got converted incorrectly (or haven't got converted).

To detect line endings used by a file on Windows, use following command on PowerShell console to display hex dump of the first 100 characters of given file (example.txt):

Get-Content -Encoding Byte -TotalCount 100 example.txt |% {Write-Host ("{0:x2} " -f $_) -NoNewline}; Write-Host

For a file with following contents in a Windows format

One
Two

it displays:

4f 6e 65 0d 0a 54 77 6f 0d 0a

Note the two sequences 0d 0a (CR + LF) indicating Windows format.

To detect line endings used by a file on Unix/Linux system use command:

xxd example.txt | head

(Alternatives are hexdump example.txt | head or od example.txt | head.)

For the same file as above, just in Unix format, it displays:

0000000: 4f6e 650a 5477 6f0a                      One.Two.

Note the character 0a (LF) indicating Unix format.

If you do not have a shell access to the remote system, download the file using binary encoding and use the PowerShell command on a local binary-identical copy.

Use these techniques to detect, what format both source and destination files have. When editing a file, detect also a format of a local temporary copy of the edited file as saved by the editor. See preferences for a location of the temporary copies.

Requesting Support

When the above does not help you understand the problem and you decide to seek further support, include all your findings, including copies of both source and destination file. When editing a file, include also a local temporary copy as saved by the editor. Ideally compress (ZIP) the files to avoid your browser altering file format, when attaching the files to support request.


(I'm the author of WinSCP)

share|improve this answer

===My Only SOLUTIONS===

Method1:

-Open file (with i.e. Notepad ++), open "Find and Replace" window [Ctrl+F] (check "Extended" under "Search Mode"),then type \r\n in first line, and \n in the second and click "Replace all" and Save.

Method2:

-in "Preferences>Transer>Default" choose "Automatic(Transfer Mode)";
-Then in "Text" window, set such conditions (but i havent tested them well): enter image description here

so, now your problem may be fixed. many people have this problem, because new lines are removed by default(in some cases) by WINSCP..

share|improve this answer

No more double linebreaks here. My solution was to uncheck the "Force text transfer mode for files in external editor" in the editor preferences.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.