class URI::FTP
FTP URI-Syntax wird in RFC1738 Abschnitt 3.2 definiert.
Diese Klasse wird aufgrund von Implementierungsunterschieden neu gestaltet; die Struktur ihres Pfades. draft-hoffman-ftp-uri-04 ist ein Entwurf, aber eine gute Zusammenfassung der De-facto-Spezifikation. datatracker.ietf.org/doc/html/draft-hoffman-ftp-uri-04
Constants
- COMPONENT
- DEFAULT_PORT
-
Ein Standardport von 21 für
URI::FTP. - TYPECODE
-
Der Typcode ist „a“, „i“ oder „d“.
- TYPECODE_PREFIX
-
Typcode-Präfix „;type=“.
Attribute
Typecode-Accessor.
Siehe URI::FTP::COMPONENT.
Öffentliche Klassenmethoden
Source
# File 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
Beschreibung
Erstellt ein neues URI::FTP-Objekt aus Komponenten mit Syntaxprüfung.
Die akzeptierten Komponenten sind userinfo, host, port, path und typecode.
Die Komponenten sollten entweder als Array oder als Hash mit Schlüsseln bereitgestellt werden, die durch Voranstellen eines Doppelpunkts vor die Komponentennamen gebildet werden.
Wenn ein Array verwendet wird, müssen die Komponenten in der Reihenfolge [userinfo, host, port, path, typecode] übergeben werden.
Wenn der bereitgestellte Pfad absolut ist, wird er so maskiert, dass er im URI absolut ist.
Beispiele
require 'uri' uri1 = URI::FTP.build(['user:password', 'ftp.example.com', nil, '/path/file.zip', 'i']) uri1.to_s # => "ftp://user:password@ftp.example.com/%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"
Source
# File lib/uri/ftp.rb, line 133 def initialize(scheme, userinfo, host, port, registry, path, opaque, query, fragment, parser = nil, arg_check = false) raise InvalidURIError unless path path = path.sub(/^\//,'') path.sub!(/^%2F/,'/') super(scheme, userinfo, host, port, registry, path, opaque, query, fragment, parser, arg_check) @typecode = nil if tmp = @path.index(TYPECODE_PREFIX) typecode = @path[tmp + TYPECODE_PREFIX.size..-1] @path = @path[0..tmp - 1] if arg_check self.typecode = typecode else self.set_typecode(typecode) end end end
Beschreibung
Erstellt ein neues URI::FTP-Objekt aus allgemeinen URL-Komponenten ohne Syntaxprüfung.
Im Gegensatz zu build() maskiert diese Methode die Pfadkomponente nicht wie von RFC1738 gefordert; stattdessen wird sie gemäß RFC2396 behandelt.
Die Argumente sind scheme, userinfo, host, port, registry, path, opaque, query und fragment in dieser Reihenfolge.
Öffentliche Instanzmethoden
Source
# File lib/uri/ftp.rb, line 240 def path return @path.sub(/^\//,'').sub(/^%2F/,'/') end
Gibt den Pfad eines FTP URI zurück.
RFC 1738 besagt ausdrücklich, dass der Pfad für einen FTP URI nicht das / enthält, das den URI-Pfad vom URI-Host trennt. Beispiel
ftp://ftp.example.com/pub/ruby
Der obige URI bedeutet, dass der Client eine Verbindung zu ftp.example.com herstellen und dann vom anfänglichen Anmeldeverzeichnis zu pub/ruby wechseln soll.
Wenn Sie zu einem absoluten Verzeichnis wechseln möchten, müssen Sie ein maskiertes / (%2F) im Pfad angeben. Beispiel
ftp://ftp.example.com/%2Fpub/ruby
Diese Methode gibt dann „/pub/ruby“ zurück.
Source
# File lib/uri/ftp.rb, line 251 def to_s save_path = nil if @typecode save_path = @path @path = @path + TYPECODE_PREFIX + @typecode end str = super if @typecode @path = save_path end return str end
Source
# File lib/uri/ftp.rb, line 208 def typecode=(typecode) check_typecode(typecode) set_typecode(typecode) typecode end
Args
v
Beschreibung
Öffentlicher Setter für den Typcode v (mit Validierung).
Siehe auch URI::FTP.check_typecode.
Verwendung
require 'uri' uri = URI.parse("ftp://john@ftp.example.com/my_file.img") #=> #<URI::FTP ftp://john@ftp.example.com/my_file.img> uri.typecode = "i" uri #=> #<URI::FTP ftp://john@ftp.example.com/my_file.img;type=i>
Geschützte Instanzmethoden
Source
# File lib/uri/ftp.rb, line 245 def set_path(v) super("/" + v.sub(/^\//, "%2F")) end
Privater Setter für den Pfad des URI::FTP.
Source
# File lib/uri/ftp.rb, line 180 def set_typecode(v) @typecode = v end
Privater Setter für den Typcode v.
Siehe auch URI::FTP.typecode=.
Private Instanzmethoden
Source
# File lib/uri/ftp.rb, line 166 def check_typecode(v) if TYPECODE.include?(v) return true else raise InvalidComponentError, "bad typecode(expected #{TYPECODE.join(', ')}): #{v}" end end
Validiert den Typcode v, gibt true oder false zurück.