From 6f871e3d226bc837e98b59649d323c6df5fc7f8a Mon Sep 17 00:00:00 2001 From: Tim Kosse Date: Wed, 28 Dec 2016 15:34:53 +0100 Subject: [PATCH] Handle failed SSH_FXP_CLOSE requests in sftp_put_file. It is possible for SSH_FXP_CLOSE requests to fail. This can happen if the server buffers writes and an error occurs flushing the data to disk while processing the SSH_FXP_CLOSE request. If the close fails, sftp_put_file now returns an error as well. --- psftp.c | 8 +++++++- sftp.c | 3 ++- sftp.h | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/psftp.c b/psftp.c index d8c4d071..7b8b540d 100644 --- a/psftp.c +++ b/psftp.c @@ -712,7 +712,13 @@ 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); + ret = fxp_close_recv(pktin, req); + if (!ret) { + if (!err) { + printf("error while closing: %s", fxp_error()); + err = 1; + } + } close_rfile(file); diff --git a/sftp.c b/sftp.c index 3357876c..5685c79e 100644 --- a/sftp.c +++ b/sftp.c @@ -658,11 +658,12 @@ struct sftp_request *fxp_close_send(struct fxp_handle *handle) return req; } -void fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req) +int fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req) { sfree(req); fxp_got_status(pktin); sftp_pkt_free(pktin); + return fxp_errtype == SSH_FX_OK; } struct sftp_request *fxp_mkdir_send(const char *path) diff --git a/sftp.h b/sftp.h index 309845b0..d9fa6939 100644 --- a/sftp.h +++ b/sftp.h @@ -149,10 +149,10 @@ struct fxp_handle *fxp_opendir_recv(struct sftp_packet *pktin, struct sftp_request *req); /* - * Close a file/dir. + * Close a file/dir. Returns 1 on success, 0 on error. */ struct sftp_request *fxp_close_send(struct fxp_handle *handle); -void fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req); +int fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req); /* * Make a directory. -- 2.45.2