fxp_close(fh);
int sftp_cmd_put(struct sftp_command *cmd) {    struct fxp_handle *fh;    char *fname, *origoutfname, *outfname;    uint64 offset;    FILE *fp;    if (cmd->nwords < 2) {	printf("put: expects a filename\n");	return 0;    }    fname = cmd->words[1];    origoutfname = (cmd->nwords == 2 ? cmd->words[1] : cmd->words[2]);    outfname = canonify(origoutfname);    if (!outfname) {	printf("%s: %s\n", origoutfname, fxp_error());	return 0;    }    fp = fopen(fname, "rb");    if (!fp) {	printf("local: unable to open %s\n", fname);        fxp_close(fh);	sfree(outfname);	return 0;    }    fh = fxp_open(outfname, SSH_FXF_WRITE | SSH_FXF_CREAT | SSH_FXF_TRUNC);    if (!fh) {	printf("%s: %s\n", outfname, fxp_error());	sfree(outfname);	return 0;    }    printf("local:%s => remote:%s\n", fname, outfname);    offset = uint64_make(0,0);    /*     * FIXME: we can use FXP_FSTAT here to get the file size, and     * thus put up a progress bar.     */    while (1) {	char buffer[4096];	int len;	len = fread(buffer, 1, sizeof(buffer), fp);	if (len == -1) {	    printf("error while reading local file\n");	    break;	} else if (len == 0) {	    break;	}	if (!fxp_write(fh, buffer, offset, len)) {	    printf("error while writing: %s\n", fxp_error());	    break;	}	offset = uint64_add32(offset, len);    }    fxp_close(fh);    fclose(fp);    sfree(outfname);    return 0;}