}
}
-void do_sftp(int mode, int modeflags, char *batchfile)
+int do_sftp(int mode, int modeflags, char *batchfile)
{
FILE *fp;
int ret;
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);
}
}
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;
}
/* ----------------------------------------------------------------------
*/
int psftp_main(int argc, char *argv[])
{
- int i;
+ int i, ret;
int portnumber = 0;
char *userhost, *user;
int mode = 0;
" to connect\n");
}
- do_sftp(mode, modeflags, batchfile);
+ ret = do_sftp(mode, modeflags, batchfile);
if (back != NULL && back->connected(backhandle)) {
char ch;
console_provide_logctx(NULL);
sk_cleanup();
- return 0;
+ return ret;
}