*/
static int sftp_ls_compare(const void *av, const void *bv)
{
- const struct fxp_name *a = (const struct fxp_name *) av;
- const struct fxp_name *b = (const struct fxp_name *) bv;
- return strcmp(a->filename, b->filename);
+ const struct fxp_name *const *a = (const struct fxp_name *const *) av;
+ const struct fxp_name *const *b = (const struct fxp_name *const *) bv;
+ return strcmp((*a)->filename, (*b)->filename);
}
int sftp_cmd_ls(struct sftp_command *cmd)
{
struct fxp_handle *dirh;
struct fxp_names *names;
- struct fxp_name *ournames;
+ struct fxp_name **ournames;
int nnames, namesize;
char *dir, *cdir;
int i;
}
for (i = 0; i < names->nnames; i++)
- ournames[nnames++] = names->names[i];
+ ournames[nnames++] = fxp_dup_name(&names->names[i]);
- names->nnames = 0; /* prevent free_names */
fxp_free_names(names);
}
fxp_close(dirh);
/*
* And print them.
*/
- for (i = 0; i < nnames; i++)
- printf("%s\n", ournames[i].longname);
+ for (i = 0; i < nnames; i++) {
+ printf("%s\n", ournames[i]->longname);
+ fxp_free_name(ournames[i]);
+ }
+ sfree(ournames);
}
sfree(cdir);
strcat(str, "\n");
fputs(str, stderr);
- exit(1);
+ cleanup_exit(1);
+}
+void modalfatalbox(char *fmt, ...)
+{
+ char str[0x100]; /* Make the size big enough */
+ va_list ap;
+ va_start(ap, fmt);
+ strcpy(str, "Fatal:");
+ vsprintf(str + strlen(str), fmt, ap);
+ va_end(ap);
+ strcat(str, "\n");
+ fputs(str, stderr);
+
+ cleanup_exit(1);
}
void connection_fatal(char *fmt, ...)
{
strcat(str, "\n");
fputs(str, stderr);
- exit(1);
+ cleanup_exit(1);
}
void ldisc_send(char *buf, int len, int interactive)
unsigned char *p = (unsigned char *) data;
unsigned len = (unsigned) datalen;
+ assert(len > 0);
+
/*
* stderr data is just spouted to local stderr and otherwise
* ignored.
winsock_ver = MAKEWORD(1, 1);
if (WSAStartup(winsock_ver, &wsadata)) {
fprintf(stderr, "Unable to initialise WinSock");
- exit(1);
+ cleanup_exit(1);
}
if (LOBYTE(wsadata.wVersion) != 1 || HIBYTE(wsadata.wVersion) != 1) {
fprintf(stderr, "WinSock version is incompatible with 1.1");
- exit(1);
+ cleanup_exit(1);
}
}
printf(" -bc output batchfile commands\n");
printf(" -be don't stop batchfile processing if errors\n");
printf(" -v show verbose messages\n");
+ printf(" -load sessname Load settings from saved session\n");
+ printf(" -l user connect with specified username\n");
printf(" -P port connect to specified port\n");
printf(" -pw passw login with specified password\n");
- exit(1);
+ printf(" -1 -2 force use of particular SSH protocol version\n");
+ printf(" -C enable compression\n");
+ printf(" -i key private key file for authentication\n");
+ printf(" -batch disable all interactive prompts\n");
+ cleanup_exit(1);
}
/*
do_defaults(NULL, &cfg);
strncpy(cfg.host, host, sizeof(cfg.host) - 1);
cfg.host[sizeof(cfg.host) - 1] = '\0';
- cfg.port = 22;
}
/*
+ * Force use of SSH. (If they got the protocol wrong we assume the
+ * port is useless too.)
+ */
+ if (cfg.protocol != PROT_SSH) {
+ cfg.protocol = PROT_SSH;
+ cfg.port = 22;
+ }
+
+ /*
+ * Enact command-line overrides.
+ */
+ cmdline_run_saved();
+
+ /*
* Trim leading whitespace off the hostname if it's there.
*/
{
printf("login as: ");
if (!fgets(cfg.username, sizeof(cfg.username), stdin)) {
fprintf(stderr, "psftp: aborting\n");
- exit(1);
+ cleanup_exit(1);
} else {
int len = strlen(cfg.username);
if (cfg.username[len - 1] == '\n')
}
}
- if (cfg.protocol != PROT_SSH)
- cfg.port = 22;
-
if (portnumber)
cfg.port = portnumber;
return 0;
}
+void cmdline_error(char *p, ...)
+{
+ va_list ap;
+ fprintf(stderr, "pscp: ");
+ va_start(ap, p);
+ vfprintf(stderr, p, ap);
+ va_end(ap);
+ fputc('\n', stderr);
+ exit(1);
+}
+
/*
* Main program. Parse arguments etc.
*/
char *batchfile = NULL;
flags = FLAG_STDERR | FLAG_INTERACTIVE;
+ cmdline_tooltype = TOOLTYPE_FILETRANSFER;
ssh_get_line = &console_get_line;
init_winsock();
sk_init();
userhost = user = NULL;
for (i = 1; i < argc; i++) {
+ int ret;
if (argv[i][0] != '-') {
- if (userhost)
- usage();
- else
- userhost = dupstr(argv[i]);
- } else if (strcmp(argv[i], "-v") == 0) {
- verbose = 1, flags |= FLAG_VERBOSE;
+ if (userhost)
+ usage();
+ else
+ userhost = dupstr(argv[i]);
+ continue;
+ }
+ ret = cmdline_process_param(argv[i], i+1<argc?argv[i+1]:NULL, 1);
+ if (ret == -2) {
+ cmdline_error("option \"%s\" requires an argument", argv[i]);
+ } else if (ret == 2) {
+ i++; /* skip next argument */
+ } else if (ret == 1) {
+ /* We have our own verbosity in addition to `flags'. */
+ if (flags & FLAG_VERBOSE)
+ verbose = 1;
} else if (strcmp(argv[i], "-h") == 0 ||
strcmp(argv[i], "-?") == 0) {
usage();
- } else if (strcmp(argv[i], "-l") == 0 && i + 1 < argc) {
- user = argv[++i];
- } else if (strcmp(argv[i], "-P") == 0 && i + 1 < argc) {
- portnumber = atoi(argv[++i]);
- } else if (strcmp(argv[i], "-pw") == 0 && i + 1 < argc) {
- console_password = argv[++i];
+ } else if (strcmp(argv[i], "-batch") == 0) {
+ console_batch_mode = 1;
} else if (strcmp(argv[i], "-b") == 0 && i + 1 < argc) {
mode = 1;
batchfile = argv[++i];
} else if (strcmp(argv[i], "-bc") == 0) {
modeflags = modeflags | 1;
- } else if (strcmp(argv[i], "-batch") == 0) {
- console_batch_mode = TRUE;
} else if (strcmp(argv[i], "-be") == 0) {
modeflags = modeflags | 2;
} else if (strcmp(argv[i], "--") == 0) {