I just replace : $result = @ssh2_sftp_rmdir($this->conn_id, $filepath); by $sftp = $this->conn_sftp; $result = rmdir("ssh2.sftp://$sftp$filepath"); to make it work, I don't know why ssh2_sftp_rmdir doesn't do the job.