summaryrefslogtreecommitdiff
path: root/sftp-client.c
diff options
context:
space:
mode:
Diffstat (limited to 'sftp-client.c')
-rw-r--r--sftp-client.c81
1 files changed, 77 insertions, 4 deletions
diff --git a/sftp-client.c b/sftp-client.c
index 5242cab03..d1e4ebacc 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"
32RCSID("$OpenBSD: sftp-client.c,v 1.10 2001/02/14 09:46:03 djm Exp $"); 32RCSID("$OpenBSD: sftp-client.c,v 1.11 2001/03/07 10:11:22 djm Exp $");
33 33
34#include "ssh.h" 34#include "ssh.h"
35#include "buffer.h" 35#include "buffer.h"
@@ -247,7 +247,8 @@ do_init(int fd_in, int fd_out)
247 } 247 }
248 248
249 buffer_free(&msg); 249 buffer_free(&msg);
250 return(0); 250
251 return(version);
251} 252}
252 253
253int 254int
@@ -483,8 +484,7 @@ do_realpath(int fd_in, int fd_out, char *path)
483 Attrib *a; 484 Attrib *a;
484 485
485 expected_id = id = msg_id++; 486 expected_id = id = msg_id++;
486 send_string_request(fd_out, id, SSH2_FXP_REALPATH, path, 487 send_string_request(fd_out, id, SSH2_FXP_REALPATH, path, strlen(path));
487 strlen(path));
488 488
489 buffer_init(&msg); 489 buffer_init(&msg);
490 490
@@ -549,6 +549,79 @@ do_rename(int fd_in, int fd_out, char *oldpath, char *newpath)
549} 549}
550 550
551int 551int
552do_symlink(int fd_in, int fd_out, char *oldpath, char *newpath)
553{
554 Buffer msg;
555 u_int status, id;
556
557 buffer_init(&msg);
558
559 /* Send rename request */
560 id = msg_id++;
561 buffer_put_char(&msg, SSH2_FXP_SYMLINK);
562 buffer_put_int(&msg, id);
563 buffer_put_cstring(&msg, oldpath);
564 buffer_put_cstring(&msg, newpath);
565 send_msg(fd_out, &msg);
566 debug3("Sent message SSH2_FXP_SYMLINK \"%s\" -> \"%s\"", oldpath,
567 newpath);
568 buffer_free(&msg);
569
570 status = get_status(fd_in, id);
571 if (status != SSH2_FX_OK)
572 error("Couldn't rename file \"%s\" to \"%s\": %s", oldpath, newpath,
573 fx2txt(status));
574
575 return(status);
576}
577
578char *
579do_readlink(int fd_in, int fd_out, char *path)
580{
581 Buffer msg;
582 u_int type, expected_id, count, id;
583 char *filename, *longname;
584 Attrib *a;
585
586 expected_id = id = msg_id++;
587 send_string_request(fd_out, id, SSH2_FXP_READLINK, path, strlen(path));
588
589 buffer_init(&msg);
590
591 get_msg(fd_in, &msg);
592 type = buffer_get_char(&msg);
593 id = buffer_get_int(&msg);
594
595 if (id != expected_id)
596 fatal("ID mismatch (%d != %d)", id, expected_id);
597
598 if (type == SSH2_FXP_STATUS) {
599 u_int status = buffer_get_int(&msg);
600
601 error("Couldn't readlink: %s", fx2txt(status));
602 return(NULL);
603 } else if (type != SSH2_FXP_NAME)
604 fatal("Expected SSH2_FXP_NAME(%d) packet, got %d",
605 SSH2_FXP_NAME, type);
606
607 count = buffer_get_int(&msg);
608 if (count != 1)
609 fatal("Got multiple names (%d) from SSH_FXP_READLINK", count);
610
611 filename = buffer_get_string(&msg, NULL);
612 longname = buffer_get_string(&msg, NULL);
613 a = decode_attrib(&msg);
614
615 debug3("SSH_FXP_READLINK %s -> %s", path, filename);
616
617 xfree(longname);
618
619 buffer_free(&msg);
620
621 return(filename);
622}
623
624int
552do_download(int fd_in, int fd_out, char *remote_path, char *local_path, 625do_download(int fd_in, int fd_out, char *remote_path, char *local_path,
553 int pflag) 626 int pflag)
554{ 627{