summaryrefslogtreecommitdiff
path: root/sftp-client.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2001-03-14 10:27:09 +1100
committerDamien Miller <djm@mindrot.org>2001-03-14 10:27:09 +1100
commit4870afd7c73a605778794378915eab0c26e8c353 (patch)
tree76d93d5002452636a8884c83ba0aba2f6c0a3f58 /sftp-client.c
parent056ddf7af3504a688c34f2daf50bcd20abfef3ba (diff)
downloadopenssh-git-4870afd7c73a605778794378915eab0c26e8c353.tar.gz
- djm@cvs.openbsd.org 2001/03/13 22:42:54
[sftp-client.c sftp-client.h sftp-glob.c sftp-glob.h sftp-int.c] sftp client filename globbing for get, put, ch{mod,grp,own}. ok markus@
Diffstat (limited to 'sftp-client.c')
-rw-r--r--sftp-client.c53
1 files changed, 49 insertions, 4 deletions
diff --git a/sftp-client.c b/sftp-client.c
index d1e4ebac..9f77d366 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.11 2001/03/07 10:11:22 djm Exp $");
+RCSID("$OpenBSD: sftp-client.c,v 1.12 2001/03/13 22:42:54 djm Exp $");
#include "ssh.h"
#include "buffer.h"
@@ -275,11 +275,13 @@ do_close(int fd_in, int fd_out, char *handle, u_int handle_len)
return(status);
}
+
int
-do_ls(int fd_in, int fd_out, char *path)
+do_lsreaddir(int fd_in, int fd_out, char *path, int printflag,
+ SFTP_DIRENT ***dir)
{
Buffer msg;
- u_int type, id, handle_len, i, expected_id;
+ u_int type, id, handle_len, i, expected_id, ents;
char *handle;
id = msg_id++;
@@ -296,6 +298,13 @@ do_ls(int fd_in, int fd_out, char *path)
if (handle == NULL)
return(-1);
+ if (dir) {
+ ents = 0;
+ *dir = xmalloc(sizeof(**dir));
+ (*dir)[0] = NULL;
+ }
+
+
for(;;) {
int count;
@@ -350,7 +359,18 @@ do_ls(int fd_in, int fd_out, char *path)
longname = buffer_get_string(&msg, NULL);
a = decode_attrib(&msg);
- printf("%s\n", longname);
+ if (printflag)
+ printf("%s\n", longname);
+
+ if (dir) {
+ *dir = xrealloc(*dir, sizeof(**dir) *
+ (ents + 2));
+ (*dir)[ents] = xmalloc(sizeof(***dir));
+ (*dir)[ents]->filename = xstrdup(filename);
+ (*dir)[ents]->longname = xstrdup(longname);
+ memcpy(&(*dir)[ents]->a, a, sizeof(*a));
+ (*dir)[++ents] = NULL;
+ }
xfree(filename);
xfree(longname);
@@ -365,6 +385,30 @@ do_ls(int fd_in, int fd_out, char *path)
}
int
+do_ls(int fd_in, int fd_out, char *path)
+{
+ return(do_lsreaddir(fd_in, fd_out, path, 1, NULL));
+}
+
+int
+do_readdir(int fd_in, int fd_out, char *path, SFTP_DIRENT ***dir)
+{
+ return(do_lsreaddir(fd_in, fd_out, path, 0, dir));
+}
+
+void free_sftp_dirents(SFTP_DIRENT **s)
+{
+ int i;
+
+ for(i = 0; s[i]; i++) {
+ xfree(s[i]->filename);
+ xfree(s[i]->longname);
+ xfree(s[i]);
+ }
+ xfree(s);
+}
+
+int
do_rm(int fd_in, int fd_out, char *path)
{
u_int status, id;
@@ -875,3 +919,4 @@ done:
buffer_free(&msg);
return status;
}
+