Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Curl to send a file over FTP. It is just a generated text file from a screen hardcopy command. When I cat the file, it displays correctly, it looks like this:

System up for    14844
 1, 0000, R D S, 0, 0, x, 0.00
 2, 0000, R D S, 0, 0, x, 0.00
 3, 0000, R D S, 0, 0, x, 0.00
 4, 0000, R D S, 0, 0, x, 0.00

However when I look at the transferred file, it is all on 1 line. Any way to fix this? Is there a command line option? This is my curl command:

curl -T ~/hardlog.log --user user:secret


share|improve this question
Are you viewing the file on the same OS? I asked because usually you get these symptoms when a file gets transferred without any changes (you can check this, their MD5sums should be the same). However your client displays the text differently. This can happen if you transfer a file from a unix like OS (which uses linefeed at the end of a line to start at a new line) to a windows or DOS like OS (which requires both LF and CR). has more information on this. – Hennes Jul 23 '13 at 20:09
up vote 2 down vote accepted

As it was already mentioned this is a classical symptom of incompatible line endings. In this case the source system is Unix-like (Linux) and the destination is Windows-like. In Windows the Unix newlines are not recognized so the text file appears as a single long line. In such cases you should do a newline conversion.

Though the FTP protocol has the newline conversion built-in Curl does not support it even if forcing ASCII transfer using -Q '+TYPE A' option.

The most convenient option would be to do the conversion on Linux before the transfer using a script:

DSTURL=              # the URL must end by a slash

unix2dos <"$SRCFILE" | curl -T- "$DSTURL$(basename "$SRCFILE")" -u"$DSTLOGIN"

If the unix2dos utility is not available on your system, you can use sed 's/$/\r/' or awk '{printf("%s\r\n",$0)}' instead. See Alternatives to unix2dos conversion.

Another option is to use a client supporting ASCII transfers like LFTP. Example:

lftp -e "put -a $HOME/hardlog.log ; exit" -u user,secret

Note: On Windows there are text editors capable of working with Unix newlines like Wordpad or some third-party ones: Notepad++, Notepad2. The last two editors can be also used for newline conversions.

share|improve this answer
Excuse me. From further research it seems that Curl does not support the text file transfers. Please let me know if my example above does not work by chance. I will adjust the reply accordingly. I can also recommend you some standalone newline conversion tools which could be run from a script together with curl. – pabouk Jul 23 '13 at 21:22
Thanks for this, you're correct (as was Hennes above) that I'm going from Linux to Windows. I tried your code and unfortunately the newlines weren't formatted correctly. I do have Notepad++, but as I'd like to automate the processing of these files, it would be nice to find a way to prep them beforehand. – McB Jul 23 '13 at 21:35
@McB Thank you for feedback. I added other options to the reply. – pabouk Jul 24 '13 at 2:51
Thanks for this! lftp would be handy, but I'm actually working on a BeagleBone and it isn't available. Since I'm trying to automate some of the setup process, downloading and making the file (which is possible) isn't ideal. I don't have unix2dos either, but I tried this code which worked: awk '{printf("%s\r\n",$0)}' hardlog.log > doslog.log – McB Jul 24 '13 at 15:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .