I assume that by "sftp client" you refer to an OpenSSH SFTP client. The "problem" is that when you press Ctrl+C, it stops the upload and cleanly closes the remote file, just as if the upload completely finished (note that it is a correct behavior and many other SFTP clients behave the same). So the server has absolutely no way to tell that the upload was interrupted.
Well strictly speaking it has, as the OpenSSH client sends a size hint to the server when creating the file. But OpenSSH server does not use nor even log that information. Though it would be pretty simple to modify its code to log the size, if that's an option for you.
See process_open
in sftp-server.c
:
a = get_attrib();
flags = flags_from_portable(pflags);
mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666;
logit("open \"%s\" flags %s mode 0%o",
name, string_from_portable(pflags), mode);
Change the logit
statement to:
logit("open \"%s\" flags %s mode 0%o size %llu",
name, string_from_portable(pflags), mode, (unsigned long long)a->size);
Note that sending the size hint is optional. While some SFTP clients will send it (e.g. OpenSSH or WinSCP), some won't (e.g. PSFTP, FileZilla, or LFTP). In such a case, you will get 0 in a->size
.
Had the client really aborted the upload (without closing the remote file cleanly, e.g. when sftp
is killed), you would be able to tell it from "forced" prefix to "close" record:
forced close "/data/README.md" bytes read 0 written 5366