I tried:

rsync -v -v -e 'ssh -p YY' ./testfile me@XXXXX:/home

Error Message

opening connection using: ssh -p YY -l me rsync ->-server -vvve.s . /home 
[sender] make_file(testfile,*,0)
send_file_list done
send_files starting
server_recv(2) starting pid=17537
rsync: connection unexpectedly closed (9 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(600)[sender=3.0.6]
_exit_cleanup(code=12, file=io.c, line=600): about to call exit(12)

This works fine:

ssh -p YY me@XXXXX

Which suggests to me the problem is neither that sshd is not running nor that port YY is firewalled. I have checked anyway.

What other problems could there be?

EDIT: The problem seems to have been "self resolving." I could not replicate the following day. I started my local computer up. Perhaps notably I had a different IP address than last time. And now rsync magically works. I'd appreciate guesses as to what it could have been in light of it going away.

  • 1
    Do you have write permission at /home of the remote server?
    – sourav c.
    May 18, 2015 at 3:53
  • Sure. When I ssh I can start doing cat and touch etc. On second thought I' not sure what you mean by remote. I'm talking about calling rsync while on a remote server to move things locally. I should have write permissions in both the original and destination folder May 18, 2015 at 22:07
  • I've been getting this error (while trying to rsync my Pelican blog to my server) every once in a while. I find that if I ssh into the server, then try the rsync again, it works fine. Not sure what happens in between.
    – Anthony C
    Oct 5, 2018 at 21:32
  • 1
    You can also get a code 12 error if the rsync binary cant be found on the remote serve,r when rsyncing over ssh. Try adding the path explcitly, using --rsync-path='/bin/rsync'
    – carpii
    Mar 21, 2022 at 23:18
  • 1
    Note: 'rsync' command should be executable at both machine for remote sync!
    – Aupr
    Nov 21, 2022 at 5:20

10 Answers 10


You can also get this error if you specify a remote path that doesn't exist.

I got this error on OS X:

$ rsync -avz public/ static:apps/myapp.com
building file list ... done
rsync: connection unexpectedly closed (8 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at /BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-47/rsync/io.c(453) [sender=2.6.9]

Turned it was simply a matter of mistyping the destination path. The apps dir didn't exist. When I changed that to static:sites/myapp.com instead (the sites dir did exist), the error went away.

It's fine if the final directory in the path doesn't exist (I could do static:sites/mynewapp.com) but it appears any preceding directory must already exist.

  • I've almost forgotten asking this question. I haven't had the same problem since. I suspect that this is what happened. Jan 6, 2016 at 20:03
  • 1
    also if you don't have rsync executable, it shows similar error. Mostly I have seen in ansibles
    – mannoj
    Nov 18, 2016 at 6:13
  • 1
    For some reason I thought rsync would create the directory if it didn't exist... I guess not - you need to create the destination directory first. If the destination path ends in a slash the directory must exist. If it does not end in a slash, the one level above it must exist. Aug 6, 2017 at 20:22
  • I had permission related problem on my remove server... Apr 24, 2018 at 13:53
  • 2
    My problem is: remote disk is full.
    – Zhang Buzz
    May 29, 2019 at 2:40

I got this error when rsync wasn't installed on the target host. The error message in my case also said rsync: command not found. A simple

sudo apt-get install rsync

on the target host solved the problem.

  • 2
    I had the a code 12 error and no message about the rsync command not being found. Once installed the error went away.
    – Hbar
    Sep 12, 2019 at 1:15
  • @abkrim, I've found this topic when I was searching Google for "Error in rsync protocol data stream". The reason was: after updating Debian from 9 to 10, rsync was gone in new system, so this exact answer really helped me. Missing rsync in target system may be a reason of similar errors — when rsync exits with code 12.
    – Ronin
    Nov 1, 2020 at 21:55
  • this is the first solution to try on a remote server! worked for me.
    – ahron
    Aug 7, 2022 at 10:16

Does your login script at the remote end produce garbage on stdout? Check this with

ssh -p YY me@XXXXX /bin/true > out.txt

If out.txt contains data, identify the offending statements in your .profile or .bashrc and wrap them in

if [ ! -t 1 ]; then
  echo garbage
  • Nada in out.txt. But I also tried that this afternoon during a period where I could not reproduce problem. May 18, 2015 at 22:04
  • I tried this at a time when I could produce the problem and I also got nothing in out.txt. Oct 14, 2015 at 15:12

This error can also happen if the path to rsync at the remote system is not what the local system assumes it to be. You can see what is happening by specifying -vv (or even more vs). If this is the problem you can specify the remote path to rsync with the --rsync-path option.

  • 2
    Thank you, this did resolve my issue... now able to rsync to my synology box with --rsync-path=/bin/rsync
    – Tracker1
    Mar 16, 2021 at 11:16
  • It worked! My Synology with the /usr/bin/rsync modified, --rsync-path=/opt/bin/rsync solved my problem. Jan 10, 2022 at 7:50
  • Thanks that what i was looking for ! :)
    – ykatchou
    Jul 4, 2022 at 17:28
  • This! In my case it was a broken rsync in the default location (Synology NAS). When I specified the user one, everything worked!
    – greatvovan
    Feb 21, 2023 at 12:21

You may need to put in the full path to the ssh binary, ie

rsync -v -v -e '/usr/bin/ssh -p YY' ./testfile me@XXXXX:/home

Though there are other possible causes.

  • Yeah I read that could happen when you have multiple instances of ssh that you could be referencing. However, the fact that it went away the next day makes this unlikely May 18, 2015 at 22:05

I hit this error because I was rsyncing to a drive that was full! Check your disk usage if the other solutions here don't help you resolve this.


I happened to run into this error for a specific file's transfer because a previously aborted rsync run seems to have corrupted the destination file (maybe due to interrupted delta/incremental changes on the destination file).

My solution was to find out which file caused the error (by using -v and/or --progress), deleting that file in the destination, then running rsync normally again.


This happens if ssh is not "in line" with rsync. For instance, on GitHub actions, on a Windows runner, if one does choco install rsync, then rsync uses another ssh client. One needs to point rsync to C:\ProgramData\chocolatey\lib\rsync\tools\bin:

rsync ... -e 'C:\ProgramData\chocolatey\lib\rsync\tools\bin\ssh.exe' ...

This resolves follwing error

rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(231) [sender=3.2.7]
Error: Process completed with exit code 12.

I was seeing this error:

rsync -e 'ssh -v'

debug1: Exit status 11


rsync error: error in rsync protocol data stream (code 12) at /BuildRoot

I was able to ssh into the remote host and found that it was out of disk space.


I got this error in rsync protocol data stream (code 12) for a pair of rsync's with different versions. So please check the rsync versions on both client and server.

In my case, local rsync was version 2.6.9 (on Mac OSX), while remote one was version 3 (can't remember now the exact version). Once I upgraded my local rsync to version 3 (using brew), the problem was fixed.

You must log in to answer this question.

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