109

I tried:

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

Error Message

opening connection using: ssh -p YY -l me 146.6.84.206 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.

user3391229
  • 1,205
  • 1
    Do you have write permission at /home of the remote server? – sourav c. May 18 '15 at 03: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 – user3391229 May 18 '15 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 05 '18 at 21:32
  • Not having enough space on the remote server can also raise this error. – Makan Feb 01 '19 at 21:55
  • 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 '22 at 23:18
  • 1
    Note: 'rsync' command should be executable at both machine for remote sync! – Aupr Nov 21 '22 at 05:20
  • In my case rsync was missing on the remote machine, so I just install it with sudo apt install -y rsync – lucidyan Apr 23 '23 at 14:58

10 Answers10

142

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.

Henrik N
  • 1,536
  • I've almost forgotten asking this question. I haven't had the same problem since. I suspect that this is what happened. – user3391229 Jan 06 '16 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 '16 at 06: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. – squarecandy Aug 06 '17 at 20:22
  • I had permission related problem on my remove server... – Chirag Purohit Apr 24 '18 at 13:53
  • Turns out on archlinux you need to have rsync on both the server and the client in order to make it work. If your server is under archlinux too, you can issue the following command: pacman -S rsync. – Amin NAIRI Mar 22 '19 at 19:45
  • 2
    My problem is: remote disk is full. – Zhang Buzz May 29 '19 at 02:40
  • You're right; I typed the dirname in uppercase – Nickolay Kondratenko Sep 14 '20 at 14:44
  • On my end it was, because I had to need a different port than 22. So also ssh command without -p 222 did not work. fixed this with parameter -e and providing the ssh command. – Alexander Taubenkorb Apr 16 '21 at 11:04
57

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 '19 at 01: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 01 '20 at 21:55
  • this is the first solution to try on a remote server! worked for me. – ahron Aug 07 '22 at 10:16
7

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
fi
Arjen
  • 366
5

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.

Mike
  • 51
  • 1
  • 1
3

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.

thomasrutter
  • 36,774
  • 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 – user3391229 May 18 '15 at 22:05
2

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.

duhaime
  • 618
2

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.

Abdull
  • 502
2

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.
koppor
  • 233
0

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.

Gui Lima
  • 38
  • 6
0

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
/Library/Caches/com.apple.xbs/Sources/rsync/rsync-51/rsync/io.c(453)
[sender=2.6.9]

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

Ravexina
  • 55,668
  • 25
  • 164
  • 183
Andy
  • 101