| Class | URI::FTP |
| In: |
lib/uri/ftp.rb
|
| Parent: | Generic |
RFC1738 section 3.2.
| DEFAULT_PORT | = | 21 | ||
| COMPONENT | = | [ :scheme, :userinfo, :host, :port, :path, :typecode | ||
| TYPECODE | = | ['a', 'i', 'd'].freeze | Typecode is, "a", "i" or "d". As for "a" the text, as for "i" binary, as for "d" the directory is displayed. "A" with the text, as for "i" being binary, is because the respective data type was called ASCII and IMAGE with the protocol of FTP. | |
| TYPECODE_PREFIX | = | ';type='.freeze |
| typecode | [R] |
Creates a new URI::FTP object from components of URI::FTP with check. It is scheme, userinfo, host, port, path and typecode. It provided by an Array or a Hash. typecode is "a", "i" or "d".
# File lib/uri/ftp.rb, line 59
59: def self.build(args)
60: tmp = Util::make_components_hash(self, args)
61:
62: if tmp[:typecode]
63: if tmp[:typecode].size == 1
64: tmp[:typecode] = TYPECODE_PREFIX + tmp[:typecode]
65: end
66: tmp[:path] << tmp[:typecode]
67: end
68:
69: return super(tmp)
70: end
Create a new URI::FTP object from ``generic’’ components with no check.
require 'uri'
p ftp = URI.parse("ftp://ftp.ruby-lang.org/pub/ruby/;type=d")
# => #<URI::FTP:0x201fad08 URL:ftp://ftp.ruby-lang.org/pub/ruby/;type=d>
p ftp.typecode
# => "d"
# File lib/uri/ftp.rb, line 86
86: def initialize(*arg)
87: super(*arg)
88: @typecode = nil
89: tmp = @path.index(TYPECODE_PREFIX)
90: if tmp
91: typecode = @path[tmp + TYPECODE_PREFIX.size..-1]
92: self.set_path(@path[0..tmp - 1])
93:
94: if arg[-1]
95: self.typecode = typecode
96: else
97: self.set_typecode(typecode)
98: end
99: end
100: end
# File lib/uri/ftp.rb, line 35
35: def self.new2(user, password, host, port, path,
36: typecode = nil, arg_check = true)
37: typecode = nil if typecode.size == 0
38: if typecode && !TYPECODE.include?(typecode)
39: raise ArgumentError,
40: "bad typecode is specified: #{typecode}"
41: end
42:
43: # do escape
44:
45: self.new('ftp',
46: [user, password],
47: host, port, nil,
48: typecode ? path + TYPECODE_PREFIX + typecode : path,
49: nil, nil, nil, arg_check)
50: end
# File lib/uri/ftp.rb, line 133
133: def to_s
134: save_path = nil
135: if @typecode
136: save_path = @path
137: @path = @path + TYPECODE_PREFIX + @typecode
138: end
139: str = super
140: if @typecode
141: @path = save_path
142: end
143:
144: return str
145: end
# File lib/uri/ftp.rb, line 118
118: def typecode=(typecode)
119: check_typecode(typecode)
120: set_typecode(typecode)
121: typecode
122: end