ruby_doc_updates-20110517-0338_vbatts.patch

Vincent Batts, 05/17/2011 12:44 PM

Download (5.37 KB)

View differences:

lib/net/ftp.rb
143 143
      end
144 144
    end
145 145

  
146
    # A setter to toggle transfers in binary mode.
147
    # +newmode+ is either +true+ or +false+
146 148
    def binary=(newmode)
147 149
      if newmode != @binary
148 150
        @binary = newmode
......
150 152
      end
151 153
    end
152 154

  
155
    # Sends a command to destination host, with the current binary sendmode type.
156
    # If binary mode is +true+, then send "TYPE I" (image)
157
    # else send "TYPE A" (ascii).
153 158
    def send_type_command
154 159
      if @binary
155 160
        voidcmd("TYPE I")
......
159 164
    end
160 165
    private :send_type_command
161 166

  
167
    # Toggles transfers in binary mode and yields to a block.
168
    # This preserves your current binary send mode, but allows a temporary
169
    # transaction with binary sendmode of +newmode+.
170
    #
171
    # +newmode+ is either +true+ or +false+
162 172
    def with_binary(newmode)
163 173
      oldmode = binary
164 174
      self.binary = newmode
......
181 191
      $stderr.puts("warning: Net::FTP#return_code= is obsolete and do nothing")
182 192
    end
183 193

  
194
    # Contructs a socket with +host+ and +port+.
195
    # If SOCKSSocket is defined and the environment (ENV)
196
    # defines SOCKS_SERVER, then a SOCKSSocket is returned,
197
    # else a TCPSocket is returned.
184 198
    def open_socket(host, port)
185 199
      if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
186 200
	@passive = true
......
219 233
      end
220 234
    end
221 235

  
236
    # If string +s+ includes the PASS command (password),
237
    # then the contents of the password are cleaned from the string using "*"
222 238
    def sanitize(s)
223 239
      if s =~ /^PASS /i
224 240
	return s[0, 5] + "*" * (s.length - 5)
......
228 244
    end
229 245
    private :sanitize
230 246

  
247
    # Ensures that +line+ has a control return / line feed (CRLF)
248
    # and writes it to the socket.
231 249
    def putline(line)
232 250
      if @debug_mode
233 251
	print "put: ", sanitize(line), "\n"
......
237 255
    end
238 256
    private :putline
239 257

  
258
    # Reads a line from the sock.
259
    # If EOF, then it will raise EOFError
240 260
    def getline
241 261
      line = @sock.readline # if get EOF, raise EOFError
242 262
      line.sub!(/(\r\n|\n|\r)\z/n, "")
......
247 267
    end
248 268
    private :getline
249 269

  
270
    # Receive a section of lines until the response code's match.
250 271
    def getmultiline
251 272
      line = getline
252 273
      buff = line
......
261 282
    end
262 283
    private :getmultiline
263 284

  
285
    # Recieves a response from the destination host.
286
    # Either returns the response code, FTPTempError,
287
    # FTPPermError, or FTPProtoError
264 288
    def getresp
265 289
      @last_response = getmultiline
266 290
      @last_response_code = @last_response[0, 3]
......
277 301
    end
278 302
    private :getresp
279 303

  
304
    # Recieves a response.
305
    # Raises FTPReplyError if the first position of the response code is not equal 2.
280 306
    def voidresp
281 307
      resp = getresp
282 308
      if resp[0] != ?2
......
305 331
      end
306 332
    end
307 333

  
334
    # Constructs and send the appropriate PORT (or EPRT) command
308 335
    def sendport(host, port)
309 336
      af = (@sock.peeraddr)[0]
310 337
      if af == "AF_INET"
......
318 345
    end
319 346
    private :sendport
320 347

  
348
    # Constructs a TCPServer socket, and sends it the PORT command
349
    #
350
    # Returns the constructed TCPServer socket
321 351
    def makeport
322 352
      sock = TCPServer.open(@sock.addr[3], 0)
323 353
      port = sock.addr[1]
......
327 357
    end
328 358
    private :makeport
329 359

  
360
    # sends the appropriate command to enable a passive connection
330 361
    def makepasv
331 362
      if @sock.peeraddr[0] == "AF_INET"
332 363
	host, port = parse227(sendcmd("PASV"))
......
338 369
    end
339 370
    private :makepasv
340 371

  
372
    # Constructs a connection for transferring data
341 373
    def transfercmd(cmd, rest_offset = nil)
342 374
      if @passive
343 375
	host, port = makepasv
......
644 676
    end
645 677

  
646 678
    #
647
    # Sends the ACCT command.  TODO: more info.
679
    # Sends the ACCT command.
680
    #
681
    # This is a less common FTP command, to send account
682
    # information if the destination host requires it.
648 683
    #
649 684
    def acct(account)
650 685
      cmd = "ACCT " + account
......
846 881
    #
847 882
    # Issues a NOOP command.
848 883
    #
884
    # Does nothing except return a response.
885
    #
849 886
    def noop
850 887
      voidcmd("NOOP")
851 888
    end
......
873 910
      @sock == nil or @sock.closed?
874 911
    end
875 912

  
913
    # handler for response code 227
914
    # (Entering Passive Mode (h1,h2,h3,h4,p1,p2))
915
    #
916
    # Returns host and port.
876 917
    def parse227(resp)
877 918
      if resp[0, 3] != "227"
878 919
	raise FTPReplyError, resp
......
892 933
    end
893 934
    private :parse227
894 935

  
936
    # handler for response code 228
937
    # (Entering Long Passive Mode)
938
    #
939
    # Returns host and port.
895 940
    def parse228(resp)
896 941
      if resp[0, 3] != "228"
897 942
	raise FTPReplyError, resp
......
924 969
    end
925 970
    private :parse228
926 971

  
972
    # handler for response code 229
973
    # (Extended Passive Mode Entered)
974
    #
975
    # Returns host and port.
927 976
    def parse229(resp)
928 977
      if resp[0, 3] != "229"
929 978
	raise FTPReplyError, resp
......
943 992
    end
944 993
    private :parse229
945 994

  
995
    # handler for response code 257
996
    # ("PATHNAME" created)
997
    #
998
    # Returns host and port.
946 999
    def parse257(resp)
947 1000
      if resp[0, 3] != "257"
948 1001
	raise FTPReplyError, resp