title: Delete a file using Ruby SFTP `remove` and `remove!`
body: <p>I am trying to old delete files from an FTP using Ruby <code>net/sftp</code>, but I keep getting an error saying the file does not exist.</p>
  
  <pre><code>:error=&gt;"Net::SFTP::StatusException (2, \"no such file\")"
  </code></pre>
  
  <p>I can manually delete files when logging in using the same creds, so I know I have permission.</p>
  
  <pre><code>require 'net/sftp'
  ftp = Net::SFTP.start(@ftp_url, @ftp_user, :password =&gt;  @ftp_pwd)
  ftp.dir.entries('somePath').each do |entry|
      begin
        age_days = (Time.now.to_i - entry.attributes.atime) / 86400
  
        if(age_days &gt; ftp_max_file_age_days)
          ftp.remove!(entry.name)
        end
  
      rescue Exception =&gt; e
        # log error here
      end
  end
  </code></pre>
  
  <p>I prefer <code>remove!</code> so everything happens synchronously in this case, but I have also tried <code>remove</code>.</p>
  
  <p>I also tried giving it the full path of the file instead of just the entry name (like <code>'somePath' + entry.name</code> instead of just <code>entry.name</code>).    I was thinking perhaps it was because I needed to change the working directory, which apparently <code>net/sftp</code> does not allow.</p>
  
  <p>Thanks in advance!</p>