This error was received when trying to write to a file opened via the SFtp.OpenFile method:
StatusMessage: Requested operation is invalid.
Failed to get write status replies (1)
The problem with most SSH/SFTP server error messages is that no information is provided. This would be an easily solved problem if the SSH server indicated WHY the operation was invalid.
The cause was determined after a lengthy investigation with the customer that experienced this problem. It turns out that a server-side file watcher process was running that locks a file when it appears. An SFTP client uploads a file by (1) opening it, (2) writing data to it, and (3) closes it. The act of opening the file creates it on the server. At this point, the file watcher process notices the new file an immediately locks it. The client-side proceeds by trying to write to the opened file, but fails because it is now locked. The "operation is invalid" turned out to be a "file is locked by another process".
It should be noted that this was a race condition: If the client can open the file, write to it, and close it quickly enough, before the file is noticed by the file watcher, then no error occurs.