Linux – SFTP encountering Bad Message

linuxsftp

I am uploading a file via sftp to a remote server. While on transfer, I got a message that says, "stalled". I killed the sftp running on my local.

The problem is, I cannot delete the partially uploaded file. when I try, rm filename.txt it returns an error:

Couldn't delete file: Bad message

Already fixed the stall and tried re-uploading the file and executed rm filename.txt but still getting the same error. Uploaded another file and tried deleting it and it was deleted. I am running debian 7 How do I delete filename.txt?

Best Answer

The problem is that when you killed the "stalled" session (assuming you forcefully killed the client) the file handle on the server remained open.

Unlike FTP(S), in fact, the SFTP protocol requires the client to explicitly close a file handle after using it. If the client fails to do that, the file on the server remains open and therefore you cannot delete it. Depending on which server software you're using, you may have to stop/restart the server process to release "zombie" handles.