lib/carrierwave/storage/ftp.rb in carrierwave-ftp-0.2.8 vs lib/carrierwave/storage/ftp.rb in carrierwave-ftp-0.3.0
- old
+ new
@@ -38,11 +38,17 @@
end
def to_file
temp_file = Tempfile.new(filename)
temp_file.binmode
- temp_file.write file.body
+ connection do |ftp|
+ ftp.chdir(::File.dirname "#{@uploader.ftp_folder}/#{path}")
+ ftp.get(filename, nil) do |data|
+ temp_file.write(data)
+ end
+ end
+ temp_file.rewind
temp_file
end
def size
size = nil
@@ -58,11 +64,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
@@ -78,19 +87,9 @@
end
rescue
end
private
-
- 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
- rescue
- end
def connection
ftp = ExFTP.new
ftp.connect(@uploader.ftp_host, @uploader.ftp_port)