diff options
Diffstat (limited to 'sftp-client.c')
-rw-r--r-- | sftp-client.c | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/sftp-client.c b/sftp-client.c index d1e4ebacc..9f77d366c 100644 --- a/sftp-client.c +++ b/sftp-client.c | |||
@@ -29,7 +29,7 @@ | |||
29 | /* XXX: copy between two remote sites */ | 29 | /* XXX: copy between two remote sites */ |
30 | 30 | ||
31 | #include "includes.h" | 31 | #include "includes.h" |
32 | RCSID("$OpenBSD: sftp-client.c,v 1.11 2001/03/07 10:11:22 djm Exp $"); | 32 | RCSID("$OpenBSD: sftp-client.c,v 1.12 2001/03/13 22:42:54 djm Exp $"); |
33 | 33 | ||
34 | #include "ssh.h" | 34 | #include "ssh.h" |
35 | #include "buffer.h" | 35 | #include "buffer.h" |
@@ -275,11 +275,13 @@ do_close(int fd_in, int fd_out, char *handle, u_int handle_len) | |||
275 | return(status); | 275 | return(status); |
276 | } | 276 | } |
277 | 277 | ||
278 | |||
278 | int | 279 | int |
279 | do_ls(int fd_in, int fd_out, char *path) | 280 | do_lsreaddir(int fd_in, int fd_out, char *path, int printflag, |
281 | SFTP_DIRENT ***dir) | ||
280 | { | 282 | { |
281 | Buffer msg; | 283 | Buffer msg; |
282 | u_int type, id, handle_len, i, expected_id; | 284 | u_int type, id, handle_len, i, expected_id, ents; |
283 | char *handle; | 285 | char *handle; |
284 | 286 | ||
285 | id = msg_id++; | 287 | id = msg_id++; |
@@ -296,6 +298,13 @@ do_ls(int fd_in, int fd_out, char *path) | |||
296 | if (handle == NULL) | 298 | if (handle == NULL) |
297 | return(-1); | 299 | return(-1); |
298 | 300 | ||
301 | if (dir) { | ||
302 | ents = 0; | ||
303 | *dir = xmalloc(sizeof(**dir)); | ||
304 | (*dir)[0] = NULL; | ||
305 | } | ||
306 | |||
307 | |||
299 | for(;;) { | 308 | for(;;) { |
300 | int count; | 309 | int count; |
301 | 310 | ||
@@ -350,7 +359,18 @@ do_ls(int fd_in, int fd_out, char *path) | |||
350 | longname = buffer_get_string(&msg, NULL); | 359 | longname = buffer_get_string(&msg, NULL); |
351 | a = decode_attrib(&msg); | 360 | a = decode_attrib(&msg); |
352 | 361 | ||
353 | printf("%s\n", longname); | 362 | if (printflag) |
363 | printf("%s\n", longname); | ||
364 | |||
365 | if (dir) { | ||
366 | *dir = xrealloc(*dir, sizeof(**dir) * | ||
367 | (ents + 2)); | ||
368 | (*dir)[ents] = xmalloc(sizeof(***dir)); | ||
369 | (*dir)[ents]->filename = xstrdup(filename); | ||
370 | (*dir)[ents]->longname = xstrdup(longname); | ||
371 | memcpy(&(*dir)[ents]->a, a, sizeof(*a)); | ||
372 | (*dir)[++ents] = NULL; | ||
373 | } | ||
354 | 374 | ||
355 | xfree(filename); | 375 | xfree(filename); |
356 | xfree(longname); | 376 | xfree(longname); |
@@ -365,6 +385,30 @@ do_ls(int fd_in, int fd_out, char *path) | |||
365 | } | 385 | } |
366 | 386 | ||
367 | int | 387 | int |
388 | do_ls(int fd_in, int fd_out, char *path) | ||
389 | { | ||
390 | return(do_lsreaddir(fd_in, fd_out, path, 1, NULL)); | ||
391 | } | ||
392 | |||
393 | int | ||
394 | do_readdir(int fd_in, int fd_out, char *path, SFTP_DIRENT ***dir) | ||
395 | { | ||
396 | return(do_lsreaddir(fd_in, fd_out, path, 0, dir)); | ||
397 | } | ||
398 | |||
399 | void free_sftp_dirents(SFTP_DIRENT **s) | ||
400 | { | ||
401 | int i; | ||
402 | |||
403 | for(i = 0; s[i]; i++) { | ||
404 | xfree(s[i]->filename); | ||
405 | xfree(s[i]->longname); | ||
406 | xfree(s[i]); | ||
407 | } | ||
408 | xfree(s); | ||
409 | } | ||
410 | |||
411 | int | ||
368 | do_rm(int fd_in, int fd_out, char *path) | 412 | do_rm(int fd_in, int fd_out, char *path) |
369 | { | 413 | { |
370 | u_int status, id; | 414 | u_int status, id; |
@@ -875,3 +919,4 @@ done: | |||
875 | buffer_free(&msg); | 919 | buffer_free(&msg); |
876 | return status; | 920 | return status; |
877 | } | 921 | } |
922 | |||