X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=psftp.c;h=5394c1fbb9150007422c8f9d0b39da66ff8aa37e;hb=510f49e405e71ba5c97875e7a019364e1ef5fac9;hp=e0e027a1abf2894cc3198c59f2cde767e6e6cd5b;hpb=89da2ddf564a93414ee9ab2df3f053608094e417;p=PuTTY.git diff --git a/psftp.c b/psftp.c index e0e027a1..5394c1fb 100644 --- a/psftp.c +++ b/psftp.c @@ -169,35 +169,6 @@ char *canonify(const char *name) } } -/* - * Return a pointer to the portion of str that comes after the last - * slash (or backslash or colon, if `local' is TRUE). - * - * This function has the annoying strstr() property of taking a const - * char * and returning a char *. You should treat it as if it was a - * pair of overloaded functions, one mapping mutable->mutable and the - * other const->const :-( - */ -static char *stripslashes(const char *str, int local) -{ - char *p; - - if (local) { - p = strchr(str, ':'); - if (p) str = p+1; - } - - p = strrchr(str, '/'); - if (p) str = p+1; - - if (local) { - p = strrchr(str, '\\'); - if (p) str = p+1; - } - - return (char *)str; -} - /* * qsort comparison routine for fxp_name structures. Sorts by real * file name. @@ -462,7 +433,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart) xfer = xfer_download_init(fh, offset); while (!xfer_done(xfer)) { void *vbuf; - int ret, len; + int len; int wpos, wlen; xfer_download_queue(xfer); @@ -520,7 +491,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) struct sftp_request *req; uint64 offset; RFile *file; - int ret, err, eof; + int err = 0, eof; struct fxp_attrs attrs; long permissions; @@ -673,6 +644,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) if (restart) { char decbuf[30]; struct fxp_attrs attrs; + int ret; req = fxp_fstat_send(fh); pktin = sftp_wait_for_reply(req); @@ -680,11 +652,12 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) if (!ret) { printf("read size of %s: %s\n", outfname, fxp_error()); + err = 1; goto cleanup; } if (!(attrs.flags & SSH_FILEXFER_ATTR_SIZE)) { printf("read size of %s: size was not given\n", outfname); - ret = 0; + err = 1; goto cleanup; } offset = attrs.size; @@ -703,9 +676,8 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) * FIXME: we can use FXP_FSTAT here to get the file size, and * thus put up a progress bar. */ - ret = 1; xfer = xfer_upload_init(fh, offset); - err = eof = 0; + eof = 0; while ((!err && !eof) || !xfer_done(xfer)) { char buffer[4096]; int len, ret; @@ -741,11 +713,16 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart) cleanup: req = fxp_close_send(fh); pktin = sftp_wait_for_reply(req); - fxp_close_recv(pktin, req); + if (!fxp_close_recv(pktin, req)) { + if (!err) { + printf("error while closing: %s", fxp_error()); + err = 1; + } + } close_rfile(file); - return ret; + return (err == 0) ? 1 : 0; } /* ---------------------------------------------------------------------- @@ -1073,6 +1050,7 @@ int sftp_cmd_ls(struct sftp_command *cmd) if (dirh == NULL) { printf("Unable to open %s: %s\n", dir, fxp_error()); + return 0; } else { nnames = namesize = 0; ournames = NULL; @@ -2394,7 +2372,7 @@ void do_sftp_cleanup() } } -void do_sftp(int mode, int modeflags, char *batchfile) +int do_sftp(int mode, int modeflags, char *batchfile) { FILE *fp; int ret; @@ -2427,8 +2405,9 @@ void do_sftp(int mode, int modeflags, char *batchfile) fp = fopen(batchfile, "r"); if (!fp) { printf("Fatal: unable to open %s\n", batchfile); - return; + return 1; } + ret = 0; while (1) { struct sftp_command *cmd; cmd = sftp_getcmd(fp, mode, modeflags); @@ -2443,8 +2422,13 @@ void do_sftp(int mode, int modeflags, char *batchfile) } } fclose(fp); - + /* + * In batch mode, and if exit on command failure is enabled, + * any command failure causes the whole of PSFTP to fail. + */ + if (ret == 0 && !(modeflags & 2)) return 2; } + return 0; } /* ---------------------------------------------------------------------- @@ -2641,6 +2625,10 @@ int sftp_senddata(char *buf, int len) back->send(backhandle, buf, len); return 1; } +int sftp_sendbuffer(void) +{ + return back->sendbuffer(backhandle); +} /* * Short description of parameters. @@ -2670,13 +2658,20 @@ static void usage(void) printf(" -hostkey aa:bb:cc:...\n"); printf(" manually specify a host key (may be repeated)\n"); printf(" -batch disable all interactive prompts\n"); + printf(" -proxycmd command\n"); + printf(" use 'command' as local proxy\n"); + printf(" -sshlog file\n"); + printf(" -sshrawlog file\n"); + printf(" log protocol details to a file\n"); cleanup_exit(1); } static void version(void) { - printf("psftp: %s\n", ver); - cleanup_exit(1); + char *buildinfo_text = buildinfo("\n"); + printf("psftp: %s\n%s\n", ver, buildinfo_text); + sfree(buildinfo_text); + exit(0); } /* @@ -2845,6 +2840,11 @@ static int psftp_connect(char *userhost, char *user, int portnumber) back = &ssh_backend; + logctx = log_init(NULL, conf); + console_provide_logctx(logctx); + + platform_psftp_pre_conn_setup(); + err = back->init(NULL, &backhandle, conf, conf_get_str(conf, CONF_host), conf_get_int(conf, CONF_port), @@ -2854,9 +2854,7 @@ static int psftp_connect(char *userhost, char *user, int portnumber) fprintf(stderr, "ssh_init: %s\n", err); return 1; } - logctx = log_init(NULL, conf); back->provide_logctx(backhandle, logctx); - console_provide_logctx(logctx); while (!back->sendok(backhandle)) { if (back->exitcode(backhandle) >= 0) return 1; @@ -2891,7 +2889,7 @@ const int share_can_be_upstream = FALSE; */ int psftp_main(int argc, char *argv[]) { - int i; + int i, ret; int portnumber = 0; char *userhost, *user; int mode = 0; @@ -2987,7 +2985,7 @@ int psftp_main(int argc, char *argv[]) " to connect\n"); } - do_sftp(mode, modeflags, batchfile); + ret = do_sftp(mode, modeflags, batchfile); if (back != NULL && back->connected(backhandle)) { char ch; @@ -3001,5 +2999,5 @@ int psftp_main(int argc, char *argv[]) console_provide_logctx(NULL); sk_cleanup(); - return 0; + return ret; }