summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/ssh/sftp-client.c32
-rw-r--r--usr.bin/ssh/sftp-client.h8
-rw-r--r--usr.bin/ssh/sftp-int.c17
-rw-r--r--usr.bin/ssh/sftp.18
-rw-r--r--usr.bin/ssh/sftp.c13
5 files changed, 47 insertions, 31 deletions
diff --git a/usr.bin/ssh/sftp-client.c b/usr.bin/ssh/sftp-client.c
index 527d23b4f1d..72e61db3bec 100644
--- a/usr.bin/ssh/sftp-client.c
+++ b/usr.bin/ssh/sftp-client.c
@@ -29,7 +29,7 @@
/* XXX: copy between two remote sites */
#include "includes.h"
-RCSID("$OpenBSD: sftp-client.c,v 1.19 2001/12/19 07:18:56 deraadt Exp $");
+RCSID("$OpenBSD: sftp-client.c,v 1.20 2002/02/05 00:00:46 djm Exp $");
#include "buffer.h"
#include "bufaux.h"
@@ -42,10 +42,6 @@ RCSID("$OpenBSD: sftp-client.c,v 1.19 2001/12/19 07:18:56 deraadt Exp $");
#include "sftp-common.h"
#include "sftp-client.h"
-/* How much data to read/write at at time during copies */
-/* XXX: what should this be? */
-#define COPY_SIZE 8192
-
/* Message ID */
static u_int msg_id = 1;
@@ -670,15 +666,14 @@ do_readlink(int fd_in, int fd_out, char *path)
int
do_download(int fd_in, int fd_out, char *remote_path, char *local_path,
- int pflag)
+ int pflag, size_t buflen)
{
- int local_fd;
+ int local_fd, status;
u_int expected_id, handle_len, mode, type, id;
u_int64_t offset;
char *handle;
Buffer msg;
Attrib junk, *a;
- int status;
a = do_stat(fd_in, fd_out, remote_path, 0);
if (a == NULL)
@@ -736,10 +731,10 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path,
buffer_put_int(&msg, id);
buffer_put_string(&msg, handle, handle_len);
buffer_put_int64(&msg, offset);
- buffer_put_int(&msg, COPY_SIZE);
+ buffer_put_int(&msg, buflen);
send_msg(fd_out, &msg);
debug3("Sent message SSH2_FXP_READ I:%d O:%llu S:%u",
- id, (unsigned long long)offset, COPY_SIZE);
+ id, (unsigned long long)offset, buflen);
buffer_clear(&msg);
@@ -767,9 +762,9 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path,
}
data = buffer_get_string(&msg, &len);
- if (len > COPY_SIZE)
+ if (len > buflen)
fatal("Received more data than asked for %d > %d",
- len, COPY_SIZE);
+ len, buflen);
debug3("In read loop, got %d offset %llu", len,
(unsigned long long)offset);
@@ -810,16 +805,15 @@ done:
int
do_upload(int fd_in, int fd_out, char *local_path, char *remote_path,
- int pflag)
+ int pflag, size_t buflen)
{
- int local_fd;
+ int local_fd, status;
u_int handle_len, id;
u_int64_t offset;
- char *handle;
+ char *handle, *data;
Buffer msg;
struct stat sb;
Attrib a;
- int status;
if ((local_fd = open(local_path, O_RDONLY, 0)) == -1) {
error("Couldn't open local file \"%s\" for reading: %s",
@@ -861,18 +855,19 @@ do_upload(int fd_in, int fd_out, char *local_path, char *remote_path,
return(-1);
}
+ data = xmalloc(buflen);
+
/* Read from local and write to remote */
offset = 0;
for (;;) {
int len;
- char data[COPY_SIZE];
/*
* Can't use atomicio here because it returns 0 on EOF, thus losing
* the last block of the file
*/
do
- len = read(local_fd, data, COPY_SIZE);
+ len = read(local_fd, data, buflen);
while ((len == -1) && (errno == EINTR || errno == EAGAIN));
if (len == -1)
@@ -904,6 +899,7 @@ do_upload(int fd_in, int fd_out, char *local_path, char *remote_path,
offset += len;
}
+ xfree(data);
if (close(local_fd) == -1) {
error("Couldn't close local file \"%s\": %s", local_path,
diff --git a/usr.bin/ssh/sftp-client.h b/usr.bin/ssh/sftp-client.h
index a322b257108..20350701c8d 100644
--- a/usr.bin/ssh/sftp-client.h
+++ b/usr.bin/ssh/sftp-client.h
@@ -1,7 +1,7 @@
-/* $OpenBSD: sftp-client.h,v 1.6 2001/06/26 06:33:01 itojun Exp $ */
+/* $OpenBSD: sftp-client.h,v 1.7 2002/02/05 00:00:46 djm Exp $ */
/*
- * Copyright (c) 2001 Damien Miller. All rights reserved.
+ * Copyright (c) 2001-2002 Damien Miller. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -94,10 +94,10 @@ char *do_readlink(int, int, char *);
* Download 'remote_path' to 'local_path'. Preserve permissions and times
* if 'pflag' is set
*/
-int do_download(int, int, char *, char *, int);
+int do_download(int, int, char *, char *, int, size_t);
/*
* Upload 'local_path' to 'remote_path'. Preserve permissions and times
* if 'pflag' is set
*/
-int do_upload(int, int, char *, char *, int);
+int do_upload(int, int, char *, char *, int , size_t);
diff --git a/usr.bin/ssh/sftp-int.c b/usr.bin/ssh/sftp-int.c
index 12a350c7b6c..c84f0a93735 100644
--- a/usr.bin/ssh/sftp-int.c
+++ b/usr.bin/ssh/sftp-int.c
@@ -26,7 +26,7 @@
/* XXX: recursive operations */
#include "includes.h"
-RCSID("$OpenBSD: sftp-int.c,v 1.41 2001/12/19 07:18:56 deraadt Exp $");
+RCSID("$OpenBSD: sftp-int.c,v 1.42 2002/02/05 00:00:46 djm Exp $");
#include <glob.h>
@@ -44,6 +44,9 @@ RCSID("$OpenBSD: sftp-int.c,v 1.41 2001/12/19 07:18:56 deraadt Exp $");
/* File to read commands from */
extern FILE *infile;
+/* Size of buffer used when copying files */
+extern size_t copy_buffer_len;
+
/* Version of server we are speaking to */
int version;
@@ -383,7 +386,8 @@ process_get(int in, int out, char *src, char *dst, char *pwd, int pflag)
goto out;
}
printf("Fetching %s to %s\n", g.gl_pathv[0], abs_dst);
- err = do_download(in, out, g.gl_pathv[0], abs_dst, pflag);
+ err = do_download(in, out, g.gl_pathv[0], abs_dst, pflag,
+ copy_buffer_len);
goto out;
}
@@ -407,7 +411,8 @@ process_get(int in, int out, char *src, char *dst, char *pwd, int pflag)
abs_dst = tmp;
printf("Fetching %s to %s\n", g.gl_pathv[i], abs_dst);
- if (do_download(in, out, g.gl_pathv[i], abs_dst, pflag) == -1)
+ if (do_download(in, out, g.gl_pathv[i], abs_dst, pflag,
+ copy_buffer_len) == -1)
err = -1;
xfree(abs_dst);
abs_dst = NULL;
@@ -465,7 +470,8 @@ process_put(int in, int out, char *src, char *dst, char *pwd, int pflag)
abs_dst = make_absolute(abs_dst, pwd);
}
printf("Uploading %s to %s\n", g.gl_pathv[0], abs_dst);
- err = do_upload(in, out, g.gl_pathv[0], abs_dst, pflag);
+ err = do_upload(in, out, g.gl_pathv[0], abs_dst, pflag,
+ copy_buffer_len);
goto out;
}
@@ -489,7 +495,8 @@ process_put(int in, int out, char *src, char *dst, char *pwd, int pflag)
abs_dst = make_absolute(tmp, pwd);
printf("Uploading %s to %s\n", g.gl_pathv[i], abs_dst);
- if (do_upload(in, out, g.gl_pathv[i], abs_dst, pflag) == -1)
+ if (do_upload(in, out, g.gl_pathv[i], abs_dst, pflag,
+ copy_buffer_len) == -1)
err = -1;
}
diff --git a/usr.bin/ssh/sftp.1 b/usr.bin/ssh/sftp.1
index 2a25603208d..49d4af574d1 100644
--- a/usr.bin/ssh/sftp.1
+++ b/usr.bin/ssh/sftp.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sftp.1,v 1.27 2002/02/04 21:53:11 djm Exp $
+.\" $OpenBSD: sftp.1,v 1.28 2002/02/05 00:00:46 djm Exp $
.\"
.\" Copyright (c) 2001 Damien Miller. All rights reserved.
.\"
@@ -31,6 +31,7 @@
.Sh SYNOPSIS
.Nm sftp
.Op Fl 1Cv
+.Op Fl B Ar buffer_size
.Op Fl b Ar batchfile
.Op Fl F Ar ssh_config
.Op Fl o Ar ssh_option
@@ -66,6 +67,11 @@ The options are as follows:
.Bl -tag -width Ds
.It Fl 1
Specify the use of protocol version 1.
+.It Fl B Ar buffer_size
+Specify the size of the buffer that
+.Nm
+uses when transferring files. Larger buffers require fewer round trips at
+the cost of higher memory consumption. The default is 32768 bytes.
.It Fl P Ar sftp_server path
Connect directly to a local
.Nm sftp-server
diff --git a/usr.bin/ssh/sftp.c b/usr.bin/ssh/sftp.c
index d985b1f2381..f1bf627e2da 100644
--- a/usr.bin/ssh/sftp.c
+++ b/usr.bin/ssh/sftp.c
@@ -24,7 +24,7 @@
#include "includes.h"
-RCSID("$OpenBSD: sftp.c,v 1.23 2002/02/04 21:53:12 djm Exp $");
+RCSID("$OpenBSD: sftp.c,v 1.24 2002/02/05 00:00:46 djm Exp $");
/* XXX: short-form remote directory listings (like 'ls -C') */
@@ -40,6 +40,7 @@ RCSID("$OpenBSD: sftp.c,v 1.23 2002/02/04 21:53:12 djm Exp $");
#include "sftp-int.h"
FILE* infile;
+size_t copy_buffer_len = 32768;
static void
connect_to_server(char *path, char **args, int *in, int *out, pid_t *sshpid)
@@ -87,7 +88,8 @@ usage(void)
{
fprintf(stderr,
"usage: sftp [-1Cv] [-b batchfile] [-F config] [-o option] [-s subsystem|path]\n"
- " [-S program] [user@]host[:file [file]]\n");
+ " [-P direct server path] [-S program] \n"
+ " [-B buffer_size] [user@]host[:file [file]]\n");
exit(1);
}
@@ -114,7 +116,7 @@ main(int argc, char **argv)
ll = SYSLOG_LEVEL_INFO;
infile = stdin; /* Read from STDIN unless changed by -b */
- while ((ch = getopt(argc, argv, "1hvCo:s:S:b:F:P:")) != -1) {
+ while ((ch = getopt(argc, argv, "1hvCo:s:S:b:B:F:P:")) != -1) {
switch (ch) {
case 'C':
addargs(&args, "-C");
@@ -152,6 +154,11 @@ main(int argc, char **argv)
case 'P':
sftp_direct = optarg;
break;
+ case 'B':
+ copy_buffer_len = strtol(optarg, &cp, 10);
+ if (copy_buffer_len == 0 || *cp != '\0')
+ fatal("Invalid buffer size \"%s\"", optarg);
+ break;
case 'h':
default:
usage();