class method
URI::FTP.build
(::Array[nil | ::String | ::Integer]) -> ::URI::Generic
({ scheme: ::String?, userinfo: ::String?, host: ::String?, port: ::Integer?, registry: ::String?, path: ::String?, opaque: ::String?, query: ::String?, fragment: ::String? }) -> instance
build(args)
lib/uri/ftp.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/uri/ftp.rb, line 96
def self.build(args)
# Fix the incoming path to be generic URL syntax
# FTP path -> URL path
# foo/bar /foo/bar
# /foo/bar /%2Ffoo/bar
#
if args.kind_of?(Array)
args[3] = '/' + args[3].sub(/^\//, '%2F')
else
args[:path] = '/' + args[:path].sub(/^\//, '%2F')
end
tmp = Util::make_components_hash(self, args)
if tmp[:typecode]
if tmp[:typecode].size == 1
tmp[:typecode] = TYPECODE_PREFIX + tmp[:typecode]
end
tmp[:path] << tmp[:typecode]
end
return super(tmp)
end
Description
Creates a new URI::FTP object from components, with syntax checking.
The components accepted are userinfo, host, port, path, and typecode.
The components should be provided either as an Array, or as a Hash with keys formed by preceding the component names with a colon.
If an Array is used, the components must be passed in the order [userinfo, host, port, path, typecode].
If the path supplied is absolute, it will be escaped in order to make it absolute in the URI.
Examples:
Example
require 'uri' uri1 = URI::FTP.build(['user:password', 'ftp.example.com', nil, '/path/file.zip', 'i']) uri1.to_s # => "ftp://user:[email protected]/%2Fpath/file.zip;type=i" uri2 = URI::FTP.build({:host => 'ftp.example.com', :path => 'ruby/src'}) uri2.to_s # => "ftp://ftp.example.com/ruby/src"