SFTP: Revamp file type detection and add truncate method

Also clean up some code