summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2001-02-14 09:46:04 +0000
committerDamien Miller <djm@cvs.openbsd.org>2001-02-14 09:46:04 +0000
commit53195031cd73d83cb0a0183780f9151305fe18db (patch)
treee4af53f5b407165f68f58cd0f534eee682a7be5d
parent65023fd224e6577b04f7e2b30166ff9885d68bab (diff)
Fix and document 'preserve modes & times' option ('-p' flag in sftp);
ok markus@
-rw-r--r--usr.bin/ssh/sftp-client.c40
-rw-r--r--usr.bin/ssh/sftp-int.c5
-rw-r--r--usr.bin/ssh/sftp.124
3 files changed, 41 insertions, 28 deletions
diff --git a/usr.bin/ssh/sftp-client.c b/usr.bin/ssh/sftp-client.c
index 8338dbc9f71..760a224e26d 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.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/usr.bin/ssh/sftp-int.c b/usr.bin/ssh/sftp-int.c
index c236f6dac20..fd649822a84 100644
--- a/usr.bin/ssh/sftp-int.c
+++ b/usr.bin/ssh/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/usr.bin/ssh/sftp.1 b/usr.bin/ssh/sftp.1
index 3b9d5124ebf..635c07b2e54 100644
--- a/usr.bin/ssh/sftp.1
+++ b/usr.bin/ssh/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