ftp: close connection and free buffers in PrepareToDie method

This avoids referencing freed memory, especially when using ftps.