From 9d4f2c808caa5af966c54de9a89c4a9ce1ef48a6 Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Thu, 15 Feb 2001 03:22:45 +0000 Subject: - djm@cvs.openbsd.org 2001/02/14 9:46:03 [sftp-client.c sftp-int.c sftp.1] Fix and document 'preserve modes & times' option ('-p' flag in sftp); ok markus@ --- ChangeLog | 6 +++++- sftp-client.c | 40 +++++++++++++++++++--------------------- sftp-int.c | 5 +++-- sftp.1 | 24 +++++++++++++++++++----- 4 files changed, 46 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 99654a04c..7da95d3c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,6 +32,10 @@ - stevesk@cvs.openbsd.org 2001/02/12 20:53:33 [sftp-int.c] lumask now works with 1 numeric arg; ok markus@, djm@ + - djm@cvs.openbsd.org 2001/02/14 9:46:03 + [sftp-client.c sftp-int.c sftp.1] + Fix and document 'preserve modes & times' option ('-p' flag in sftp); + ok markus@ 20010214 - (djm) Don't try to close PAM session or delete credentials if the @@ -3960,4 +3964,4 @@ - Wrote replacements for strlcpy and mkdtemp - Released 1.0pre1 -$Id: ChangeLog,v 1.768 2001/02/15 03:19:56 mouring Exp $ +$Id: ChangeLog,v 1.769 2001/02/15 03:22:45 mouring Exp $ diff --git a/sftp-client.c b/sftp-client.c index 8338dbc9f..760a224e2 100644 --- a/sftp-client.c +++ b/sftp-client.c @@ -29,7 +29,7 @@ /* XXX: copy between two remote sites */ #include "includes.h" -RCSID("$OpenBSD: sftp-client.c,v 1.9 2001/02/10 00:41:46 djm Exp $"); +RCSID("$OpenBSD: sftp-client.c,v 1.10 2001/02/14 09:46:03 djm Exp $"); #include "ssh.h" #include "buffer.h" @@ -577,20 +577,6 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path, return(errno); } - /* Override umask and utimes if asked */ - if (pflag && fchmod(local_fd, mode) == -1) - error("Couldn't set mode on \"%s\": %s", local_path, - strerror(errno)); - if (pflag && (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME)) { - struct timeval tv; - - tv.tv_sec = a->atime; - tv.tv_usec = a->mtime; - if (utimes(local_path, &tv) == -1) - error("Can't set times on \"%s\": %s", local_path, - strerror(errno)); - } - buffer_init(&msg); /* Send open request */ @@ -675,6 +661,20 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path, } status = do_close(fd_in, fd_out, handle, handle_len); + /* Override umask and utimes if asked */ + if (pflag && fchmod(local_fd, mode) == -1) + error("Couldn't set mode on \"%s\": %s", local_path, + strerror(errno)); + if (pflag && (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME)) { + struct timeval tv[2]; + tv[0].tv_sec = a->atime; + tv[1].tv_sec = a->mtime; + tv[0].tv_usec = tv[1].tv_usec = 0; + if (utimes(local_path, tv) == -1) + error("Can't set times on \"%s\": %s", local_path, + strerror(errno)); + } + done: close(local_fd); buffer_free(&msg); @@ -735,10 +735,6 @@ do_upload(int fd_in, int fd_out, char *local_path, char *remote_path, return(-1); } - /* Override umask and utimes if asked */ - if (pflag) - do_fsetstat(fd_in, fd_out, handle, handle_len, &a); - /* Read from local and write to remote */ offset = 0; for(;;) { @@ -791,6 +787,10 @@ do_upload(int fd_in, int fd_out, char *local_path, char *remote_path, goto done; } + /* Override umask and utimes if asked */ + if (pflag) + do_fsetstat(fd_in, fd_out, handle, handle_len, &a); + status = do_close(fd_in, fd_out, handle, handle_len); done: @@ -798,5 +798,3 @@ done: buffer_free(&msg); return status; } - - diff --git a/sftp-int.c b/sftp-int.c index c236f6dac..fd649822a 100644 --- a/sftp-int.c +++ b/sftp-int.c @@ -28,7 +28,7 @@ /* XXX: recursive operations */ #include "includes.h" -RCSID("$OpenBSD: sftp-int.c,v 1.21 2001/02/12 20:53:33 stevesk Exp $"); +RCSID("$OpenBSD: sftp-int.c,v 1.22 2001/02/14 09:46:03 djm Exp $"); #include "buffer.h" #include "xmalloc.h" @@ -204,11 +204,12 @@ parse_getput_flags(const char **cpp, int *pflag) /* Check for flags */ if (cp[0] == '-' && cp[1] && strchr(WHITESPACE, cp[2])) { switch (cp[1]) { + case 'p': case 'P': *pflag = 1; break; default: - error("Invalid flag -%c", *cp); + error("Invalid flag -%c", cp[1]); return(-1); } cp += 2; diff --git a/sftp.1 b/sftp.1 index 3b9d5124e..635c07b2e 100644 --- a/sftp.1 +++ b/sftp.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sftp.1,v 1.6 2001/02/10 00:45:52 djm Exp $ +.\" $OpenBSD: sftp.1,v 1.7 2001/02/14 09:46:03 djm Exp $ .\" .\" Copyright (c) 2001 Damien Miller. All rights reserved. .\" @@ -94,13 +94,20 @@ to must be a numeric UID. .It Ic help Display help text. -.It Ic get Ar remote-path Op Ar local-path +.It Xo Ic get +.Op Ar flags +.Ar remote-path +.Op Ar local-path +.Xc Retrieve the .Ar remote-path and store it on the local machine. If the local path name is not specified, it is given the same name it has on the -remote machine. +remote machine. If the +.Fl P +flag is specified, then the file's full permission and access time are +copied too. .It Ic lls Op Ar ls-options Op Ar path Display local directory listing of either .Ar path @@ -124,11 +131,18 @@ Set local umask to .It Ic mkdir Ar path Create remote directory specified by .Ar path . -.It Ic put Ar local-path Op Ar remote-path +.It Xo Ic put +.Op Ar flags +.Ar local-path +.Op Ar local-path +.Xc Upload .Ar local-path and store it on the remote machine. If the remote path name is not specified, -it is given the same name it has on the local machine. +it is given the same name it has on the local machine. If the +.Fl P +flag is specified, then the file's full permission and access time are +copied too. .It Ic pwd Display remote working directory. .It Ic exit -- cgit v1.2.3