Class: Net::FTPS::Implicit
- Inherits:
-
Net::FTP
- Object
- Net::FTP
- Net::FTPS::Implicit
- Defined in:
- lib/net/ftps_implicit.rb
Constant Summary collapse
- FTP_PORT =
990
Instance Attribute Summary collapse
-
#data_protection ⇒ Object
Returns the value of attribute data_protection.
Class Method Summary collapse
Instance Method Summary collapse
- #abort ⇒ Object
- #close ⇒ Object
- #connect(host, port = FTP_PORT) ⇒ Object
- #get_data(sock, blocksize = 1024) ⇒ Object
-
#initialize(host = nil, user = nil, passwd = nil, acct = nil, verify_mode = OpenSSL::SSL::VERIFY_PEER) ⇒ Implicit
constructor
A new instance of Implicit.
- #quit ⇒ Object
-
#retrbinary(cmd, blocksize, rest_offset = nil) ⇒ Object
:yield: data.
-
#retrlines(cmd) ⇒ Object
:yield: line.
-
#storbinary(cmd, file, blocksize, rest_offset = nil, &block) ⇒ Object
Puts the connection into binary (image) mode, issues the given server-side command (such as “STOR myfile”), and sends the contents of the file named
fileto the server. -
#storlines(cmd, file, &block) ⇒ Object
Puts the connection into ASCII (text) mode, issues the given server-side command (such as “STOR myfile”), and sends the contents of the file named
fileto the server, one line at a time.
Constructor Details
#initialize(host = nil, user = nil, passwd = nil, acct = nil, verify_mode = OpenSSL::SSL::VERIFY_PEER) ⇒ Implicit
Returns a new instance of Implicit.
20 21 22 23 24 25 26 27 28 |
# File 'lib/net/ftps_implicit.rb', line 20 def initialize(host=nil, user=nil, passwd=nil, acct=nil, verify_mode=OpenSSL::SSL::VERIFY_PEER) super(host, user, passwd, acct) @passive = true @binary = false @debug_mode = true @data_protection = 'P' @data_protected = false @verify_mode = verify_mode end |
Instance Attribute Details
#data_protection ⇒ Object
Returns the value of attribute data_protection.
29 30 31 |
# File 'lib/net/ftps_implicit.rb', line 29 def data_protection @data_protection end |
Class Method Details
.open(host, user = nil, passwd = nil, acct = nil, verify_mode = OpenSSL::SSL::VERIFY_PEER) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/net/ftps_implicit.rb', line 31 def self.open(host, user=nil, passwd=nil, acct=nil, verify_mode=OpenSSL::SSL::VERIFY_PEER) if block_given? ftps = new(host, user, passwd, acct, verify_mode) begin yield ftps ensure ftps.close end else new(host, user, passwd, acct, verify_mode) end end |
Instance Method Details
#abort ⇒ Object
80 81 82 |
# File 'lib/net/ftps_implicit.rb', line 80 def abort voidcmd("ABOR") rescue EOFError end |
#close ⇒ Object
88 89 90 91 |
# File 'lib/net/ftps_implicit.rb', line 88 def close @sock.close # SSL @sock.io.close # TCP end |
#connect(host, port = FTP_PORT) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/net/ftps_implicit.rb', line 67 def connect(host, port=FTP_PORT) @sock = open_socket(host, port) mon_initialize getresp at_exit { if @sock && !@sock.closed? voidcmd("ABOR") rescue EOFError voidcmd("QUIT") rescue EOFError close end } end |
#get_data(sock, blocksize = 1024) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/net/ftps_implicit.rb', line 103 def get_data(sock,blocksize=1024) timeout = 10 starttime = Time.now buffer = '' timeouts = 0 catch :done do loop do event = select([sock],nil,nil,0.5) if event.nil? # nil would be a timeout, we'd do nothing and start loop over. Of course here we really have no timeout... timeouts += 0.5 break if timeouts > timeout else event[0].each do |sock| # Iterate through all sockets that have pending activity if sock.eof? # Socket's been closed by the client throw :done else buffer << sock.readpartial(blocksize) if block_given? # we're in line-by-line mode lines = buffer.split(/\r?\n/) buffer = buffer =~ /\n$/ ? '' : lines.pop lines.each do |line| yield(line) end end end end end end end sock.close buffer end |
#quit ⇒ Object
84 85 86 |
# File 'lib/net/ftps_implicit.rb', line 84 def quit voidcmd("QUIT") rescue EOFError end |
#retrbinary(cmd, blocksize, rest_offset = nil) ⇒ Object
:yield: data
93 94 95 96 97 98 99 100 101 |
# File 'lib/net/ftps_implicit.rb', line 93 def retrbinary(cmd, blocksize, rest_offset = nil) # :yield: data synchronize do voidcmd("TYPE I") conn = transfercmd(cmd, rest_offset) data = get_data(conn,blocksize) yield(data) voidresp end end |
#retrlines(cmd) ⇒ Object
:yield: line
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/net/ftps_implicit.rb', line 136 def retrlines(cmd) # :yield: line synchronize do voidcmd("TYPE A") voidcmd("STRU F") voidcmd("MODE S") conn = transfercmd(cmd) get_data(conn) do |line| yield(line) end getresp end end |
#storbinary(cmd, file, blocksize, rest_offset = nil, &block) ⇒ Object
Puts the connection into binary (image) mode, issues the given server-side command (such as “STOR myfile”), and sends the contents of the file named file to the server. If the optional block is given, it also passes it the data, in chunks of blocksize characters.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/net/ftps_implicit.rb', line 155 def storbinary(cmd, file, blocksize, rest_offset = nil, &block) # :yield: data if rest_offset file.seek(rest_offset, IO::SEEK_SET) end synchronize do voidcmd("TYPE I") conn = transfercmd(cmd, rest_offset) loop do buf = file.read(blocksize) break if buf == nil conn.write(buf) yield(buf) if block end conn.close # closes the SSL conn.io.close # closes the TCP below it voidresp end end |
#storlines(cmd, file, &block) ⇒ Object
Puts the connection into ASCII (text) mode, issues the given server-side command (such as “STOR myfile”), and sends the contents of the file named file to the server, one line at a time. If the optional block is given, it also passes it the lines.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/net/ftps_implicit.rb', line 180 def storlines(cmd, file, &block) # :yield: line synchronize do voidcmd("TYPE A") conn = transfercmd(cmd) loop do buf = file.gets break if buf == nil if buf[-2, 2] != CRLF buf = buf.chomp + CRLF end conn.write(buf) yield(buf) if block end conn.close # closes the SSL conn.io.close # closes the TCP below it voidresp end end |