-@@ -1148,8 +1198,9 @@ static void recv_generator(char *fname,
- * mode based on the local permissions and some heuristics. */
- if (!preserve_perms) {
- int exists = statret == 0
-- && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
-- file->mode = dest_mode(file->mode, st.st_mode, exists);
-+ && S_ISDIR(sx.st.st_mode) == S_ISDIR(file->mode);
-+ file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms,
-+ exists);
- }
-
- if (S_ISDIR(file->mode)) {
-@@ -1158,8 +1209,8 @@ static void recv_generator(char *fname,
+@@ -1149,8 +1199,8 @@ static void recv_generator(char *fname,