--- /tmp/tramp-sh.el.orig	2013-04-20 13:04:19.218624784 -0700
+++ /tmp/tramp-sh.el	2013-04-20 13:35:30.310631054 -0700
@@ -2963,7 +2963,8 @@
 		  ;; epa-file gets confused.
 		  (let (file-name-handler-alist
 			(coding-system-for-write 'binary))
-		    (write-region (point-min) (point-max) tmpfile2))
+                    (with-current-buffer (tramp-get-buffer v)
+                      (write-region (point-min) (point-max) tmpfile2)))
 		  (tramp-with-progress-reporter
 		      v 3 (format "Decoding remote file %s with command %s"
 				  filename loc-dec)
@@ -3229,7 +3230,7 @@
 		      (tramp-send-command
 		       v
 		       (format
-			(concat rem-dec " <<'EOF'\n%sEOF")
+			(concat rem-dec ">%s <<'EOF'\n%sEOF")
 			(tramp-shell-quote-argument localname)
 			(buffer-string)))
 		      (tramp-barf-unless-okay
@@ -5018,8 +5019,7 @@
 	       "(%s <%%s | \"%s\")"
 	     "(%s <%%s | %s)")
 	   compress coding))
-	 ((string-match "decoding" prop)
-	  (format "%s >%%s" coding))
+	 ((string-match "decoding" prop) coding)
 	 (t
 	  (format "%s <%%s" coding)))))))
 
