- stevesk@cvs.openbsd.org 2002/02/04 20:41:16
[ssh-agent.1]
more sync for default ssh-add identities; ok markus@
+ - djm@cvs.openbsd.org 2002/02/05 00:00:46
+ [sftp.1 sftp.c sftp-client.c sftp-client.h sftp-int.c]
+ Add "-B" option to specify copy buffer length (default 32k); ok markus@
20020205
- (djm) Cleanup after sync:
/* 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"
#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;
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)
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, (u_int64_t)offset, COPY_SIZE);
+ id, (u_int64_t)offset, buflen);
buffer_clear(&msg);
}
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,
(u_int64_t)offset);
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",
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)
offset += len;
}
+ xfree(data);
if (close(local_fd) == -1) {
error("Couldn't close local file \"%s\": %s", local_path,
-/* $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
* 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);
/* 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 "buffer.h"
#include "xmalloc.h"
/* 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;
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;
}
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;
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;
}
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;
}
-.\" $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.
.\"
.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
.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
#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') */
#endif
FILE* infile;
+size_t copy_buffer_len = 32768;
static void
connect_to_server(char *path, char **args, int *in, int *out, pid_t *sshpid)
{
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);
}
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");
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();