Passing SFTP options when using SCP

Chris Rapier rapier at psc.edu
Thu Dec 8 10:06:43 AEDT 2022


I just tried this patch and it seems to work as expected. The only thing 
I changed was to give initial values to sftp_copy_buflen and 
sftp_nrequests. If they aren't initialized is there some default that 
would kick into effect on the receiving side?

I'll be testing this in more detail once I have better access to my the 
testbed I use. Are you likely to be using 'X' as the command line 
argument if this gets rolled into a release? I just want to make sure my 
arguments don't conflict if I do a release earlier than you do.

Chris

On 12/6/22 8:17 PM, Damien Miller wrote:
> On Tue, 6 Dec 2022, Chris Rapier wrote:
> 
>> Hey all,
>>
>> I might have missed this but is there any effective way of passing sftp
>> options when using scp? For example, increasing the number of outstanding
>> requests which would be the -R command line option in sftp.
>>
>> For my purposes I'm mostly looking at sending different buffer (-B) and
>> request (-R) options. Even better if there is a way to do that
>> programmatically. For example, in sftp-client.c I can just change
>> DEFAULT_NUM_REQUESTS to whatever value I like and every sftp transfer I
>> initiate will use that.
>>
>> Just curious. If there isn't I'll try to come up with a method and share it
>> when I'm done.
> 
> There are no options to do this ATM and at least one of the option
> letters that sftp uses already has meaning for sftp. These are
> rarely used, so maybe it makes sent to put them behind a single
> getopt chat that accepts multiple arguments.
> 
> diff --git a/scp.c b/scp.c
> index c7194c2..4e50be1 100644
> --- a/scp.c
> +++ b/scp.c
> @@ -150,6 +150,10 @@ char *ssh_program = _PATH_SSH_PROGRAM;
>   pid_t do_cmd_pid = -1;
>   pid_t do_cmd_pid2 = -1;
>   
> +/* SFTP copy parameters */
> +size_t sftp_copy_buflen;
> +size_t sftp_nrequests;
> +
>   /* Needed for sftp */
>   volatile sig_atomic_t interrupted = 0;
>   
> @@ -419,7 +423,7 @@ int
>   main(int argc, char **argv)
>   {
>   	int ch, fflag, tflag, status, n;
> -	char **newargv, *argv0;
> +	char **newargv, *argv0, *cp;
>   	const char *errstr;
>   	extern char *optarg;
>   	extern int optind;
> @@ -452,7 +456,7 @@ main(int argc, char **argv)
>   
>   	fflag = Tflag = tflag = 0;
>   	while ((ch = getopt(argc, argv,
> -	    "12346ABCTdfOpqRrstvD:F:J:M:P:S:c:i:l:o:")) != -1) {
> +	    "12346ABCTdfOpqRrstvD:F:J:M:P:S:c:i:l:o:X:")) != -1) {
>   		switch (ch) {
>   		/* User-visible flags. */
>   		case '1':
> @@ -533,6 +537,23 @@ main(int argc, char **argv)
>   			addargs(&remote_remote_args, "-q");
>   			showprogress = 0;
>   			break;
> +		case 'X':
> +			if (strncmp(optarg, "buffer=", 7) == 0) {
> +				sftp_copy_buflen = strtol(optarg + 7, &cp, 10);
> +				if (sftp_copy_buflen == 0 || *cp != '\0') {
> +					fatal("Invalid buffer size \"%s\"",
> +					     optarg);
> +				}
> +			} else if (strncmp(optarg, "nrequests=", 10) == 0) {
> +				sftp_nrequests = strtol(optarg + 10, &cp, 10);
> +				if (sftp_nrequests == 0 || *cp != '\0') {
> +					fatal("Invalid number of requests "
> +					    "\"%s\"", optarg);
> +				}
> +			} else {
> +				fatal("Invalid -X option");
> +			}
> +			break;
>   
>   		/* Server options. */
>   		case 'd':
> @@ -941,7 +962,8 @@ do_sftp_connect(char *host, char *user, int port, char *sftp_direct,
>   		    reminp, remoutp, pidp) < 0)
>   			return NULL;
>   	}
> -	return do_init(*reminp, *remoutp, 32768, 64, limit_kbps);
> +	return do_init(*reminp, *remoutp,
> +	    sftp_copy_buflen, sftp_nrequests, limit_kbps);
>   }
>   
>   void


More information about the openssh-unix-dev mailing list