summaryrefslogtreecommitdiff
path: root/sftp.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2010-01-08 17:10:36 +1100
committerDarren Tucker <dtucker@zip.com.au>2010-01-08 17:10:36 +1100
commit210631922f86192e99aefe6cf985155d61f44965 (patch)
treee75402d89edcac72670b4df842fdb75eb8e409b1 /sftp.c
parentc3dc404113c4bb3d3a86bdee47f15e5c881d12a4 (diff)
- djm@cvs.openbsd.org 2009/11/20 00:54:01
[sftp.c] bz#1588 change "Connecting to host..." message to "Connected to host." and delay it until after the sftp protocol connection has been established. Avoids confusing sequence of messages when the underlying ssh connection experiences problems. ok dtucker@
Diffstat (limited to 'sftp.c')
-rw-r--r--sftp.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/sftp.c b/sftp.c
index 75b16b27e..85e5505b5 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp.c,v 1.111 2009/08/18 18:36:21 djm Exp $ */ 1/* $OpenBSD: sftp.c,v 1.112 2009/11/20 00:54:01 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -68,18 +68,15 @@ typedef void EditLine;
68#include "sftp-common.h" 68#include "sftp-common.h"
69#include "sftp-client.h" 69#include "sftp-client.h"
70 70
71#define DEFAULT_COPY_BUFLEN 32768 /* Size of buffer for up/download */
72#define DEFAULT_NUM_REQUESTS 64 /* # concurrent outstanding requests */
73
71/* File to read commands from */ 74/* File to read commands from */
72FILE* infile; 75FILE* infile;
73 76
74/* Are we in batchfile mode? */ 77/* Are we in batchfile mode? */
75int batchmode = 0; 78int batchmode = 0;
76 79
77/* Size of buffer used when copying files */
78size_t copy_buffer_len = 32768;
79
80/* Number of concurrent outstanding requests */
81size_t num_requests = 64;
82
83/* PID of ssh transport process */ 80/* PID of ssh transport process */
84static pid_t sshpid = -1; 81static pid_t sshpid = -1;
85 82
@@ -187,7 +184,7 @@ static const struct CMD cmds[] = {
187 { NULL, -1} 184 { NULL, -1}
188}; 185};
189 186
190int interactive_loop(int fd_in, int fd_out, char *file1, char *file2); 187int interactive_loop(struct sftp_conn *, char *file1, char *file2);
191 188
192/* ARGSUSED */ 189/* ARGSUSED */
193static void 190static void
@@ -1472,12 +1469,11 @@ prompt(EditLine *el)
1472#endif 1469#endif
1473 1470
1474int 1471int
1475interactive_loop(int fd_in, int fd_out, char *file1, char *file2) 1472interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
1476{ 1473{
1477 char *pwd; 1474 char *pwd;
1478 char *dir = NULL; 1475 char *dir = NULL;
1479 char cmd[2048]; 1476 char cmd[2048];
1480 struct sftp_conn *conn;
1481 int err, interactive; 1477 int err, interactive;
1482 EditLine *el = NULL; 1478 EditLine *el = NULL;
1483#ifdef USE_LIBEDIT 1479#ifdef USE_LIBEDIT
@@ -1501,10 +1497,6 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
1501 } 1497 }
1502#endif /* USE_LIBEDIT */ 1498#endif /* USE_LIBEDIT */
1503 1499
1504 conn = do_init(fd_in, fd_out, copy_buffer_len, num_requests);
1505 if (conn == NULL)
1506 fatal("Couldn't initialise connection to server");
1507
1508 pwd = do_realpath(conn, "."); 1500 pwd = do_realpath(conn, ".");
1509 if (pwd == NULL) 1501 if (pwd == NULL)
1510 fatal("Need cwd"); 1502 fatal("Need cwd");
@@ -1694,6 +1686,9 @@ main(int argc, char **argv)
1694 arglist args; 1686 arglist args;
1695 extern int optind; 1687 extern int optind;
1696 extern char *optarg; 1688 extern char *optarg;
1689 struct sftp_conn *conn;
1690 size_t copy_buffer_len = DEFAULT_COPY_BUFLEN;
1691 size_t num_requests = DEFAULT_NUM_REQUESTS;
1697 1692
1698 /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */ 1693 /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
1699 sanitise_stdfd(); 1694 sanitise_stdfd();
@@ -1837,20 +1832,27 @@ main(int argc, char **argv)
1837 addargs(&args, "%s", (sftp_server != NULL ? 1832 addargs(&args, "%s", (sftp_server != NULL ?
1838 sftp_server : "sftp")); 1833 sftp_server : "sftp"));
1839 1834
1840 if (!batchmode)
1841 fprintf(stderr, "Connecting to %s...\n", host);
1842 connect_to_server(ssh_program, args.list, &in, &out); 1835 connect_to_server(ssh_program, args.list, &in, &out);
1843 } else { 1836 } else {
1844 args.list = NULL; 1837 args.list = NULL;
1845 addargs(&args, "sftp-server"); 1838 addargs(&args, "sftp-server");
1846 1839
1847 if (!batchmode)
1848 fprintf(stderr, "Attaching to %s...\n", sftp_direct);
1849 connect_to_server(sftp_direct, args.list, &in, &out); 1840 connect_to_server(sftp_direct, args.list, &in, &out);
1850 } 1841 }
1851 freeargs(&args); 1842 freeargs(&args);
1852 1843
1853 err = interactive_loop(in, out, file1, file2); 1844 conn = do_init(in, out, copy_buffer_len, num_requests);
1845 if (conn == NULL)
1846 fatal("Couldn't initialise connection to server");
1847
1848 if (!batchmode) {
1849 if (sftp_direct == NULL)
1850 fprintf(stderr, "Connected to %s.\n", host);
1851 else
1852 fprintf(stderr, "Attached to %s.\n", sftp_direct);
1853 }
1854
1855 err = interactive_loop(conn, file1, file2);
1854 1856
1855#if !defined(USE_PIPES) 1857#if !defined(USE_PIPES)
1856 shutdown(in, SHUT_RDWR); 1858 shutdown(in, SHUT_RDWR);