struct sftp_request *req, *rreq;
struct fxp_xfer *xfer;
uint64 offset;
- FILE *fp;
+ WFile *file;
int ret, shown_err = FALSE;
/*
fh = fxp_open_recv(pktin, rreq);
if (!fh) {
- printf("%s: %s\n", fname, fxp_error());
+ printf("%s: open for read: %s\n", fname, fxp_error());
return 0;
}
if (restart) {
- fp = fopen(outfname, "rb+");
+ file = open_existing_wfile(outfname, NULL);
} else {
- fp = fopen(outfname, "wb");
+ file = open_new_file(outfname);
}
- if (!fp) {
+ if (!file) {
printf("local: unable to open %s\n", outfname);
sftp_register(req = fxp_close_send(fh));
}
if (restart) {
- long posn;
- fseek(fp, 0L, SEEK_END);
- posn = ftell(fp);
- printf("reget: restarting at file position %ld\n", posn);
- offset = uint64_make(0, posn);
+ char decbuf[30];
+ if (seek_file(file, uint64_make(0,0) , FROM_END) == -1) {
+ printf("reget: cannot restart %s - file too large\n",
+ outfname);
+ sftp_register(req = fxp_close_send(fh));
+ rreq = sftp_find_request(pktin = sftp_recv());
+ assert(rreq == req);
+ fxp_close_recv(pktin, rreq);
+
+ return 0;
+ }
+
+ offset = get_file_posn(file);
+ uint64_decimal(offset, decbuf);
+ printf("reget: restarting at file position %s\n", decbuf);
} else {
offset = uint64_make(0, 0);
}
wpos = 0;
while (wpos < len) {
- wlen = fwrite(buf + wpos, 1, len - wpos, fp);
+ wlen = write_to_file(file, buf + wpos, len - wpos);
if (wlen <= 0) {
printf("error while writing local file\n");
ret = 0;
xfer_cleanup(xfer);
- fclose(fp);
+ close_wfile(file);
sftp_register(req = fxp_close_send(fh));
rreq = sftp_find_request(pktin = sftp_recv());
struct sftp_packet *pktin;
struct sftp_request *req, *rreq;
uint64 offset;
- FILE *fp;
+ RFile *file;
int ret, err, eof;
/*
return 1;
}
- fp = fopen(fname, "rb");
- if (!fp) {
+ file = open_existing_file(fname, NULL, NULL, NULL);
+ if (!file) {
printf("local: unable to open %s\n", fname);
return 0;
}
fh = fxp_open_recv(pktin, rreq);
if (!fh) {
- printf("%s: %s\n", outfname, fxp_error());
+ printf("%s: open for write: %s\n", outfname, fxp_error());
return 0;
}
offset = attrs.size;
uint64_decimal(offset, decbuf);
printf("reput: restarting at file position %s\n", decbuf);
- if (uint64_compare(offset, uint64_make(0, LONG_MAX)) > 0) {
- printf("reput: remote file is larger than we can deal with\n");
- return 0;
- }
- if (fseek(fp, offset.lo, SEEK_SET) != 0)
- fseek(fp, 0, SEEK_END); /* *shrug* */
+
+ if (seek_file((WFile *)file, offset, FROM_START) != 0)
+ seek_file((WFile *)file, uint64_make(0,0), FROM_END); /* *shrug* */
} else {
offset = uint64_make(0, 0);
}
int len, ret;
while (xfer_upload_ready(xfer) && !err && !eof) {
- len = fread(buffer, 1, sizeof(buffer), fp);
+ len = read_from_file(file, buffer, sizeof(buffer));
if (len == -1) {
printf("error while reading local file\n");
err = 1;
assert(rreq == req);
fxp_close_recv(pktin, rreq);
- fclose(fp);
+ close_rfile(file);
return ret;
}
while ( (newname = sftp_wildcard_get_filename(swcm)) != NULL ) {
cname = canonify(newname);
if (!cname) {
- printf("%s: %s\n", newname, fxp_error());
+ printf("%s: canonify: %s\n", newname, fxp_error());
ret = 0;
}
matched = TRUE;
} else {
cname = canonify(unwcfname);
if (!cname) {
- printf("%s: %s\n", filename, fxp_error());
+ printf("%s: canonify: %s\n", filename, fxp_error());
ret = 0;
}
ret = func(ctx, cname);
return 0;
}
- if (back != NULL && back->socket(backhandle) != NULL) {
+ if (back != NULL && back->connected(backhandle)) {
char ch;
back->special(backhandle, TS_EOF);
sftp_recvdata(&ch, 1);
cdir = canonify(dir);
if (!cdir) {
- printf("%s: %s\n", dir, fxp_error());
+ printf("%s: canonify: %s\n", dir, fxp_error());
sfree(unwcdir);
return 0;
}
dir = canonify(cmd->words[1]);
if (!dir) {
- printf("%s: %s\n", dir, fxp_error());
+ printf("%s: canonify: %s\n", dir, fxp_error());
return 0;
}
fname = canonify(origwfname);
if (!fname) {
- printf("%s: %s\n", origwfname, fxp_error());
+ printf("%s: canonify: %s\n", origwfname, fxp_error());
sfree(unwcfname);
return 0;
}
outfname = canonify(origoutfname);
if (!outfname) {
- printf("%s: %s\n", origoutfname, fxp_error());
+ printf("%s: canonify: %s\n", origoutfname, fxp_error());
if (wcm) {
sfree(wfname);
finish_wildcard_matching(wcm);
for (i = 1; i < cmd->nwords; i++) {
dir = canonify(cmd->words[i]);
if (!dir) {
- printf("%s: %s\n", dir, fxp_error());
+ printf("%s: canonify: %s\n", dir, fxp_error());
return 0;
}
newname = dupcat(ctx->dstfname, "/", p, NULL);
newcanon = canonify(newname);
if (!newcanon) {
- printf("%s: %s\n", newname, fxp_error());
+ printf("%s: canonify: %s\n", newname, fxp_error());
sfree(newname);
return 0;
}
ctx->dstfname = canonify(cmd->words[cmd->nwords-1]);
if (!ctx->dstfname) {
- printf("%s: %s\n", ctx->dstfname, fxp_error());
+ printf("%s: canonify: %s\n", ctx->dstfname, fxp_error());
return 0;
}
}
while (outlen > 0) {
- if (ssh_sftp_loop_iteration() < 0)
+ if (back->exitcode(backhandle) >= 0 || ssh_sftp_loop_iteration() < 0)
return 0; /* doom */
}
strncpy(cfg.username, user, sizeof(cfg.username) - 1);
cfg.username[sizeof(cfg.username) - 1] = '\0';
}
- if (!cfg.username[0]) {
- /* FIXME: leave this to ssh.c? */
- int ret;
- prompts_t *p = new_prompts(NULL);
- p->to_server = TRUE;
- p->name = dupstr("SSH login name");
- add_prompt(p, dupstr("login as: "), TRUE, lenof(cfg.username));
- ret = get_userpass_input(p, NULL, 0);
- assert(ret >= 0);
- if (!ret) {
- free_prompts(p);
- fprintf(stderr, "psftp: no username, aborting\n");
- cleanup_exit(1);
- } else {
- memcpy(cfg.username, p->prompts[0]->result, lenof(cfg.username));
- free_prompts(p);
- }
- }
if (portnumber)
cfg.port = portnumber;
do_sftp(mode, modeflags, batchfile);
- if (back != NULL && back->socket(backhandle) != NULL) {
+ if (back != NULL && back->connected(backhandle)) {
char ch;
back->special(backhandle, TS_EOF);
sftp_recvdata(&ch, 1);