X-Git-Url: http://andersk.mit.edu/gitweb/openssh.git/blobdiff_plain/acc9d6d7d54986d615bfa1fc62b1274cca0a4601..2e4fb373fccee2e5a296d484189169914f6e07d8:/sftp-client.c 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); @@ -364,6 +384,30 @@ do_ls(int fd_in, int fd_out, char *path) return(0); } +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) { @@ -875,3 +919,4 @@ done: buffer_free(&msg); return status; } +