lib/rsh/drivers/ssh.rb in rsh2-0.0.2 vs lib/rsh/drivers/ssh.rb in rsh2-0.0.3
- old
+ new
@@ -7,26 +7,26 @@
raise "invalid ssh options!" unless options[:ssh].is_a?(Hash)
end
def upload_file from_local_path, to_remote_path
remote do |ssh, sftp|
- sftp.upload! from_local_path, to_remote_path
+ sftp.upload! from_local_path, fix_path(to_remote_path)
end
end
def download_file from_remote_path, to_local_path
File.open to_local_path, "w" do |out|
remote do |ssh, sftp|
- sftp.download! from_remote_path, out #, :recursive => true
+ sftp.download! fix_path(from_remote_path), out #, :recursive => true
end
end
end
def exist? remote_file_path
remote do |ssh, sftp|
begin
- fattrs = sftp.stat! remote_file_path
+ fattrs = sftp.stat! fix_path(remote_file_path)
fattrs.directory? or fattrs.file? or fattrs.symlink?
rescue Net::SFTP::StatusException
false
end
end
@@ -34,11 +34,11 @@
alias_method :directory_exist?, :exist?
alias_method :file_exist?, :exist?
def remove_file remote_file_path
remote do |ssh, sftp|
- sftp.remove! remote_file_path
+ sftp.remove! fix_path(remote_file_path)
end
end
def exec command
remote do |ssh, sftp|
@@ -80,20 +80,34 @@
exec "rm -r #{path}"
end
def upload_directory from_local_path, to_remote_path
remote do |ssh, sftp|
- sftp.upload! from_local_path, to_remote_path
+ sftp.upload! from_local_path, fix_path(to_remote_path)
end
end
def download_directory from_remote_path, to_local_path
remote do |ssh, sftp|
- sftp.download! from_remote_path, to_local_path, :recursive => true
+ sftp.download! fix_path(from_remote_path), to_local_path, :recursive => true
end
end
protected
+ def fix_path path
+ path.sub(/^\~/, home)
+ end
+
+ def home
+ unless @home
+ command = 'cd ~; pwd'
+ code, stdout, stderr = exec command
+ raise "can't execute '#{command}'!" unless code == 0
+ @home = stdout.gsub("\n", '')
+ end
+ @home
+ end
+
# taken from here http://stackoverflow.com/questions/3386233/how-to-get-exit-status-with-rubys-netssh-library/3386375#3386375
def hacked_exec!(ssh, command, &block)
stdout_data = ""
stderr_data = ""
exit_code = nil
\ No newline at end of file