I am using WinSCP 5.9 (Build 6786) and am trying to implement an mime filter in the openssh sftp-server code. Since I only know if the file that is loaded onto my server is allowed after the writing process started, I return a Permission Denied status during writing, as soon as the mime type can be determined from the file.
However, most of the time WinSCP returns a "packet was garbled on decryption" error. WinSCP is terminated and in the log "Fatal error while disposing the SFTP queue" can be read.
Even if it doesn't, it still sometimes procedes as if everything was fine and tries to rename the file, if it had been opened as <filename>.filepart. Only in very few cases it displays the error correctly and finishes after calling close.
How can I stop the writing process correctly?