lib/carrierwave/storage/ftp.rb in carrierwave-ftp-0.3.1 vs lib/carrierwave/storage/ftp.rb in carrierwave-ftp-0.4.0

- old
+ new

@@ -1,7 +1,8 @@ require 'carrierwave' require 'carrierwave/storage/ftp/ex_ftp' +require 'carrierwave/storage/ftp/ex_ftptls' module CarrierWave module Storage class FTP < Abstract def store!(file) @@ -24,10 +25,13 @@ def store(file) connection do |ftp| ftp.mkdir_p(::File.dirname "#{@uploader.ftp_folder}/#{path}") ftp.chdir(::File.dirname "#{@uploader.ftp_folder}/#{path}") ftp.put(file.path, filename) + if @uploader.ftp_chmod + ftp.sendcmd("SITE CHMOD #{@uploader.permissions.to_s(8)} #{@uploader.ftp_folder}/#{path}") + end end end def url "#{@uploader.ftp_url}/#{path}" @@ -89,11 +93,16 @@ end private def connection - ftp = ExFTP.new + if @uploader.ftp_tls + ftp = ExFTPTLS.new + ftp.ssl_context = DoubleBagFTPS.create_ssl_context(:verify_mode => OpenSSL::SSL::VERIFY_NONE) + else + ftp = ExFTP.new + end ftp.connect(@uploader.ftp_host, @uploader.ftp_port) begin ftp.passive = @uploader.ftp_passive ftp.login(@uploader.ftp_user, @uploader.ftp_passwd) @@ -116,17 +125,21 @@ add_config :ftp_user add_config :ftp_passwd add_config :ftp_folder add_config :ftp_url add_config :ftp_passive + add_config :ftp_tls + add_config :ftp_chmod configure do |config| config.storage_engines[:ftp] = "CarrierWave::Storage::FTP" config.ftp_host = "localhost" config.ftp_port = 21 config.ftp_user = "anonymous" config.ftp_passwd = "" config.ftp_folder = "/" config.ftp_url = "http://localhost" config.ftp_passive = false + config.ftp_tls = false + config.ftp_chmod = true end end