lib/carrierwave/storage/sftp.rb in carrierwave-ftp-0.2.8 vs lib/carrierwave/storage/sftp.rb in carrierwave-ftp-0.3.0
- old
+ new
@@ -37,11 +37,14 @@
end
def to_file
temp_file = Tempfile.new(filename)
temp_file.binmode
- temp_file.write file.body
+ connection do |sftp|
+ sftp.download!(full_path, temp_file)
+ end
+ temp_file.rewind
temp_file
end
def size
size = nil
@@ -56,11 +59,14 @@
def exists?
size ? true : false
end
def read
- file.body
+ file = to_file
+ content = file.read
+ file.close
+ content
end
def content_type
@content_type || file.content_type
end
@@ -76,20 +82,15 @@
rescue
end
private
- def full_path
- "#{@uploader.sftp_folder}/#{path}"
+ def use_ssl?
+ @uploader.sftp_url.start_with?('https')
end
- def file
- require 'net/http'
- url = URI.parse(self.url)
- req = Net::HTTP::Get.new(url.path)
- Net::HTTP.start(url.host, url.port) do |http|
- http.request(req)
- end
+ def full_path
+ "#{@uploader.sftp_folder}/#{path}"
end
def connection
sftp = Net::SFTP.start(@uploader.sftp_host, @uploader.sftp_user, @uploader.sftp_options)
yield sftp