X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/ee07dce4bc01900faf5c9b14e14803705e239b5d..8a9ec85763809cd3e849d3b00750ba74222dee18:/pscp.c diff --git a/pscp.c b/pscp.c index ddf23ecc..054e437b 100644 --- a/pscp.c +++ b/pscp.c @@ -45,6 +45,7 @@ static int using_sftp = 0; static Backend *back; static void *backhandle; static Conf *conf; +int sent_eof = FALSE; static void source(char *src); static void rsource(char *src); @@ -214,6 +215,19 @@ int from_backend_untrusted(void *frontend_handle, const char *data, int len) assert(!"Unexpected call to from_backend_untrusted()"); return 0; /* not reached */ } +int from_backend_eof(void *frontend) +{ + /* + * We expect to be the party deciding when to close the + * connection, so if we see EOF before we sent it ourselves, we + * should panic. + */ + if (!sent_eof) { + connection_fatal(frontend, + "Received unexpected end-of-file from server"); + } + return FALSE; +} static int ssh_scp_recv(unsigned char *buf, int len) { outptr = buf; @@ -298,6 +312,7 @@ static void bump(char *fmt, ...) if (back != NULL && back->connected(backhandle)) { char ch; back->special(backhandle, TS_EOF); + sent_eof = TRUE; ssh_scp_recv((unsigned char *) &ch, 1); } @@ -450,7 +465,7 @@ static void do_cmd(char *host, char *user, char *cmd) if (try_scp) { /* Fallback is to use the provided scp command. */ fallback_cmd_is_sftp = 0; - conf_set_str(conf, CONF_remote_cmd2, "sftp"); + conf_set_str(conf, CONF_remote_cmd2, cmd); conf_set_int(conf, CONF_ssh_subsys2, FALSE); } else { /* Since we're not going to try SCP, we may as well try @@ -2268,9 +2283,12 @@ int psftp_main(int argc, char *argv[]) preserve = 1; } else if (strcmp(argv[i], "-q") == 0) { statistics = 0; - } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-?") == 0) { + } else if (strcmp(argv[i], "-h") == 0 || + strcmp(argv[i], "-?") == 0 || + strcmp(argv[i], "--help") == 0) { usage(); - } else if (strcmp(argv[i], "-V") == 0) { + } else if (strcmp(argv[i], "-V") == 0 || + strcmp(argv[i], "--version") == 0) { version(); } else if (strcmp(argv[i], "-ls") == 0) { list = 1; @@ -2314,6 +2332,7 @@ int psftp_main(int argc, char *argv[]) if (back != NULL && back->connected(backhandle)) { char ch; back->special(backhandle, TS_EOF); + sent_eof = TRUE; ssh_scp_recv((unsigned char *) &ch, 1); } random_save_seed();