Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File remains locked if scp returns non-zero #20

Open
burnzoire opened this issue Oct 22, 2014 · 0 comments
Open

File remains locked if scp returns non-zero #20

burnzoire opened this issue Oct 22, 2014 · 0 comments

Comments

@burnzoire
Copy link

I'm using the upload! method to push zip archives to a remote location. After getting a SCP did not finish successfully (1): (Net::SCP::Error) I am finding that the file I tried to upload is locked.

Here is the method I am using for my Rails API application:

def copy_to_remote (local_path, remote_path, ssh)  
    session_options = {
      :password => ssh[:password],
      #:verbose => Logger::DEBUG,
      :timeout => 10
    }

    begin  
      # copy to remote location
      Net::SCP.start(ssh[:host], ssh[:user], session_options) do |scp|
        scp.upload!(local_path, remote_path)
      end

    rescue Net::SSH::AuthenticationFailed
      raise Exceptions::ArchiveAuthenticationFailed, "Could not authenticate with remote location"

    rescue Net::SSH::ConnectionTimeout
      raise Exceptions::ArchiveConnectionTimeout, "Connection timed out with remote location"

    rescue Net::SSH::Disconnect
      raise Exceptions::ArchiveDisconnect, "Lost connection with remote location"

    rescue Net::SCP::Error => e
      raise Exceptions::ArchiveCopyError, "Could not copy archive to remote location - #{e.message}"

    ensure
      # can't remove as file is locked. 
      FileUtils.rm_rf(local_path) if File::exists?(local_path)        
    end

  end

I have tried all kinds of permutations of calling upload, I have also tried manually closing the channel but I can't seem to get it to lose its grip on my file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant