Skip to content

Commit 6c431e8

Browse files
committed
address scp's sftp mode buf len limitations
1 parent 9231e35 commit 6c431e8

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

scp.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,12 @@ pid_t do_cmd_pid = -1;
184184
pid_t do_cmd_pid2 = -1;
185185

186186
/* SFTP copy parameters */
187+
#ifdef WINDOWS
188+
// match DEFAULT_COPY_BUFLEN from sftp-client.c unless overriden below with -X input
189+
size_t sftp_copy_buflen = 32768;
190+
#else
187191
size_t sftp_copy_buflen;
192+
#endif // WINDOWS
188193
size_t sftp_nrequests;
189194

190195
/* Needed for sftp */
@@ -770,6 +775,16 @@ main(int argc, char **argv)
770775
optarg + 7, strerror(errno));
771776
}
772777
sftp_copy_buflen = (size_t)llv;
778+
#ifdef WINDOWS
779+
size_t max_sftp_buf_len = 204800;
780+
if (sftp_copy_buflen > max_sftp_buf_len) {
781+
if (verbose_mode)
782+
fmprintf(stderr,
783+
"Buffer value of %d is too large for Win32-OpenSSH. Setting buffer to %d\n",
784+
sftp_copy_buflen, max_sftp_buf_len);
785+
sftp_copy_buflen = max_sftp_buf_len;
786+
}
787+
#endif // WINDOWS
773788
} else if (strncmp(optarg, "nrequests=", 10) == 0) {
774789
llv = strtonum(optarg + 10, 1, 256 * 1024,
775790
&errstr);
@@ -1199,7 +1214,7 @@ do_sftp_connect(char *host, char *user, int port, char *sftp_direct,
11991214
get_zone_identifier(host);
12001215
#endif // WINDOWS
12011216
return do_init(*reminp, *remoutp,
1202-
sftp_copy_buflen, sftp_nrequests, limit_kbps);
1217+
sftp_copy_buflen, sftp_nrequests, limit_kbps);
12031218
}
12041219

12051220
void

0 commit comments

Comments
 (0)