lib/backup/storage/ftp.rb in backup-ssh-4.1.10 vs lib/backup/storage/ftp.rb in backup-ssh-4.4.0

- old
+ new

@@ -13,19 +13,29 @@ ## # Server IP Address and FTP port attr_accessor :ip, :port ## - # use passive mode? + # Use passive mode? attr_accessor :passive_mode + ## + # Configure connection open and read timeouts. + # Net::FTP's open_timeout and read_timeout will both be configured using + # this setting. + # @!attribute [rw] timeout + # @param [Integer|Float] + # @return [Integer|Float] + attr_accessor :timeout + def initialize(model, storage_id = nil) super @port ||= 21 @path ||= 'backups' @passive_mode ||= false + @timeout ||= nil path.sub!(/^~\//, '') end private @@ -40,9 +50,13 @@ if Net::FTP.const_defined?(:FTP_PORT) Net::FTP.send(:remove_const, :FTP_PORT) end; Net::FTP.send(:const_set, :FTP_PORT, port) Net::FTP.open(ip, username, password) do |ftp| + if timeout + ftp.open_timeout = timeout + ftp.read_timeout = timeout + end ftp.passive = true if passive_mode yield ftp end end