class Chef::Provider::RemoteFile::FTP
Attributes
Public Class Methods
Source
# File lib/chef/provider/remote_file/ftp.rb, line 37 def initialize(uri, new_resource, current_resource) @uri = uri @new_resource = new_resource @current_resource = current_resource validate_typecode! validate_path! end
Public Instance Methods
Source
# File lib/chef/provider/remote_file/ftp.rb, line 77 def directories parse_path if @directories.nil? @directories end
Source
# File lib/chef/provider/remote_file/ftp.rb, line 87 def fetch with_connection do get end end
Source
# File lib/chef/provider/remote_file/ftp.rb, line 82 def filename parse_path if @filename.nil? @filename end
Source
# File lib/chef/provider/remote_file/ftp.rb, line 93 def ftp @ftp ||= Net::FTP.new end
Source
# File lib/chef/provider/remote_file/ftp.rb, line 69 def pass if uri.userinfo CGI.unescape(uri.password) else nil end end
Source
# File lib/chef/provider/remote_file/ftp.rb, line 57 def typecode uri.typecode end
Source
# File lib/chef/provider/remote_file/ftp.rb, line 53 def use_passive_mode? ! new_resource.ftp_active_mode end
Source
# File lib/chef/provider/remote_file/ftp.rb, line 61 def user if uri.userinfo CGI.unescape(uri.user) else "anonymous" end end
Private Instance Methods
Source
# File lib/chef/provider/remote_file/ftp.rb, line 127 def connect # The access sequence is defined by RFC 1738 ftp.connect(hostname, port) ftp.passive = use_passive_mode? ftp.login(user, pass) directories.each do |cwd| ftp.voidcmd("CWD #{cwd}") end end
Source
# File lib/chef/provider/remote_file/ftp.rb, line 137 def disconnect ftp.close end
Source
# File lib/chef/provider/remote_file/ftp.rb, line 142 def get tempfile = Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile if typecode ftp.voidcmd("TYPE #{typecode.upcase}") end ftp.getbinaryfile(filename, tempfile.path) tempfile.close if tempfile tempfile end
Fetches using Net::FTP, returns a Tempfile with the content
Source
# File lib/chef/provider/remote_file/ftp.rb, line 156 def parse_path path = uri.path.sub(%r{\A/}, "%2F") # re-encode the beginning slash because uri library decodes it. directories = path.split(%r{/}, -1) directories.each do |d| d.gsub!(/%([0-9A-Fa-f][0-9A-Fa-f])/) { [$1].pack("H2") } end unless filename = directories.pop raise ArgumentError, "no filename: #{path.inspect}" end if filename.length == 0 || filename.end_with?( "/" ) raise ArgumentError, "no filename: #{path.inspect}" end @directories, @filename = directories, filename end
Source
# File lib/chef/provider/remote_file/ftp.rb, line 152 def proxy_uri(uri) Chef::Config.proxy_uri("ftp", hostname, port) end
Source
# File lib/chef/provider/remote_file/ftp.rb, line 123 def validate_path! parse_path end
Source
# File lib/chef/provider/remote_file/ftp.rb, line 116 def validate_typecode! # Only support ascii and binary types if typecode && /\A[ai]\z/ !~ typecode raise ArgumentError, "invalid typecode: #{typecode.inspect}" end end
Source
# File lib/chef/provider/remote_file/ftp.rb, line 107 def with_connection with_proxy_env do connect yield end ensure disconnect end
Source
# File lib/chef/provider/remote_file/ftp.rb, line 99 def with_proxy_env saved_socks_env = ENV["SOCKS_SERVER"] ENV["SOCKS_SERVER"] = proxy_uri(@uri).to_s yield ensure ENV["SOCKS_SERVER"] = saved_socks_env end