ruby_doc_updates-20110516_vbatts.patch

Vincent Batts, 05/16/2011 10:17 PM

Download (20.8 KB)

View differences:

lib/net/ftp.rb
136 136
      @sock = NullSocket.new
137 137
      @logged_in = false
138 138
      if host
139
	connect(host)
140
	if user
141
	  login(user, passwd, acct)
142
	end
139
        connect(host)
140
        if user
141
          login(user, passwd, acct)
142
        end
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
	@passive = true
187
	return SOCKSSocket.open(host, port)
200
        @passive = true
201
        return SOCKSSocket.open(host, port)
188 202
      else
189
	return TCPSocket.open(host, port)
203
        return TCPSocket.open(host, port)
190 204
      end
191 205
    end
192 206
    private :open_socket
......
199 213
    #
200 214
    def connect(host, port = FTP_PORT)
201 215
      if @debug_mode
202
	print "connect: ", host, ", ", port, "\n"
216
        print "connect: ", host, ", ", port, "\n"
203 217
      end
204 218
      synchronize do
205
	@sock = open_socket(host, port)
206
	voidresp
219
        @sock = open_socket(host, port)
220
        voidresp
207 221
      end
208 222
    end
209 223

  
......
212 226
    #
213 227
    def set_socket(sock, get_greeting = true)
214 228
      synchronize do
215
	@sock = sock
216
	if get_greeting
217
	  voidresp
218
	end
229
        @sock = sock
230
        if get_greeting
231
          voidresp
232
        end
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
	return s[0, 5] + "*" * (s.length - 5)
240
        return s[0, 5] + "*" * (s.length - 5)
225 241
      else
226
	return s
242
        return s
227 243
      end
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
	print "put: ", sanitize(line), "\n"
251
        print "put: ", sanitize(line), "\n"
234 252
      end
235 253
      line = line + CRLF
236 254
      @sock.write(line)
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, "")
243 263
      if @debug_mode
244
	print "get: ", sanitize(line), "\n"
264
        print "get: ", sanitize(line), "\n"
245 265
      end
246 266
      return line
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
253 274
      if line[3] == ?-
254
	  code = line[0, 3]
255
	begin
256
	  line = getline
257
	  buff << "\n" << line
258
	end until line[0, 3] == code and line[3] != ?-
275
        code = line[0, 3]
276
        begin
277
          line = getline
278
          buff << "\n" << line
279
        end until line[0, 3] == code and line[3] != ?-
259 280
      end
260 281
      return buff << "\n"
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]
267 291
      case @last_response_code
268 292
      when /\A[123]/
269
	return @last_response
293
        return @last_response
270 294
      when /\A4/
271
	raise FTPTempError, @last_response
295
        raise FTPTempError, @last_response
272 296
      when /\A5/
273
	raise FTPPermError, @last_response
297
        raise FTPPermError, @last_response
274 298
      else
275
	raise FTPProtoError, @last_response
299
        raise FTPProtoError, @last_response
276 300
      end
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
283
	raise FTPReplyError, resp
309
        raise FTPReplyError, resp
284 310
      end
285 311
    end
286 312
    private :voidresp
......
290 316
    #
291 317
    def sendcmd(cmd)
292 318
      synchronize do
293
	putline(cmd)
294
	return getresp
319
        putline(cmd)
320
        return getresp
295 321
      end
296 322
    end
297 323

  
......
300 326
    #
301 327
    def voidcmd(cmd)
302 328
      synchronize do
303
	putline(cmd)
304
	voidresp
329
        putline(cmd)
330
        voidresp
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"
311
	cmd = "PORT " + (host.split(".") + port.divmod(256)).join(",")
338
        cmd = "PORT " + (host.split(".") + port.divmod(256)).join(",")
312 339
      elsif af == "AF_INET6"
313
	cmd = sprintf("EPRT |2|%s|%d|", host, port)
340
        cmd = sprintf("EPRT |2|%s|%d|", host, port)
314 341
      else
315
	raise FTPProtoError, host
342
        raise FTPProtoError, host
316 343
      end
317 344
      voidcmd(cmd)
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
	host, port = parse227(sendcmd("PASV"))
363
        host, port = parse227(sendcmd("PASV"))
333 364
      else
334
	host, port = parse229(sendcmd("EPSV"))
335
	#     host, port = parse228(sendcmd("LPSV"))
365
        host, port = parse229(sendcmd("EPSV"))
366
        #     host, port = parse228(sendcmd("LPSV"))
336 367
      end
337 368
      return host, port
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
	host, port = makepasv
344
	conn = open_socket(host, port)
345
	if @resume and rest_offset
346
	  resp = sendcmd("REST " + rest_offset.to_s)
347
	  if resp[0] != ?3
348
	    raise FTPReplyError, resp
349
	  end
350
	end
351
	resp = sendcmd(cmd)
375
        host, port = makepasv
376
        conn = open_socket(host, port)
377
        if @resume and rest_offset
378
          resp = sendcmd("REST " + rest_offset.to_s)
379
          if resp[0] != ?3
380
            raise FTPReplyError, resp
381
          end
382
        end
383
        resp = sendcmd(cmd)
352 384
        # skip 2XX for some ftp servers
353 385
        resp = getresp if resp[0] == ?2
354
	if resp[0] != ?1
355
	  raise FTPReplyError, resp
356
	end
386
        if resp[0] != ?1
387
          raise FTPReplyError, resp
388
        end
357 389
      else
358
	sock = makeport
359
	if @resume and rest_offset
360
	  resp = sendcmd("REST " + rest_offset.to_s)
361
	  if resp[0] != ?3
362
	    raise FTPReplyError, resp
363
	  end
364
	end
365
	resp = sendcmd(cmd)
390
        sock = makeport
391
        if @resume and rest_offset
392
          resp = sendcmd("REST " + rest_offset.to_s)
393
          if resp[0] != ?3
394
            raise FTPReplyError, resp
395
          end
396
        end
397
        resp = sendcmd(cmd)
366 398
        # skip 2XX for some ftp servers
367 399
        resp = getresp if resp[0] == ?2
368
	if resp[0] != ?1
369
	  raise FTPReplyError, resp
370
	end
371
	conn = sock.accept
372
	sock.close
400
        if resp[0] != ?1
401
          raise FTPReplyError, resp
402
        end
403
        conn = sock.accept
404
        sock.close
373 405
      end
374 406
      return conn
375 407
    end
......
385 417
    #
386 418
    def login(user = "anonymous", passwd = nil, acct = nil)
387 419
      if user == "anonymous" and passwd == nil
388
	passwd = "anonymous@"
420
        passwd = "anonymous@"
389 421
      end
390 422

  
391 423
      resp = ""
392 424
      synchronize do
393
	resp = sendcmd('USER ' + user)
394
	if resp[0] == ?3
425
        resp = sendcmd('USER ' + user)
426
        if resp[0] == ?3
395 427
          raise FTPReplyError, resp if passwd.nil?
396
	  resp = sendcmd('PASS ' + passwd)
397
	end
398
	if resp[0] == ?3
428
          resp = sendcmd('PASS ' + passwd)
429
        end
430
        if resp[0] == ?3
399 431
          raise FTPReplyError, resp if acct.nil?
400
	  resp = sendcmd('ACCT ' + acct)
401
	end
432
          resp = sendcmd('ACCT ' + acct)
433
        end
402 434
      end
403 435
      if resp[0] != ?2
404
	raise FTPReplyError, resp
436
        raise FTPReplyError, resp
405 437
      end
406 438
      @welcome = resp
407 439
      send_type_command
......
416 448
    #
417 449
    def retrbinary(cmd, blocksize, rest_offset = nil) # :yield: data
418 450
      synchronize do
419
	with_binary(true) do
451
        with_binary(true) do
420 452
          conn = transfercmd(cmd, rest_offset)
421 453
          loop do
422 454
            data = conn.read(blocksize)
......
437 469
    #
438 470
    def retrlines(cmd) # :yield: line
439 471
      synchronize do
440
	with_binary(false) do
472
        with_binary(false) do
441 473
          conn = transfercmd(cmd)
442 474
          loop do
443 475
            line = conn.gets
......
461 493
        file.seek(rest_offset, IO::SEEK_SET)
462 494
      end
463 495
      synchronize do
464
	with_binary(true) do
496
        with_binary(true) do
465 497
          conn = transfercmd(cmd)
466 498
          loop do
467 499
            buf = file.read(blocksize)
......
490 522
    #
491 523
    def storlines(cmd, file, &block) # :yield: line
492 524
      synchronize do
493
	with_binary(false) do
525
        with_binary(false) do
494 526
          conn = transfercmd(cmd)
495 527
          loop do
496 528
            buf = file.gets
......
521 553
    # chunks.
522 554
    #
523 555
    def getbinaryfile(remotefile, localfile = File.basename(remotefile),
524
		      blocksize = DEFAULT_BLOCKSIZE) # :yield: data
556
                      blocksize = DEFAULT_BLOCKSIZE) # :yield: data
525 557
      result = nil
526 558
      if localfile
527 559
        if @resume
......
535 567
        result = ""
536 568
      end
537 569
      begin
538
	f.binmode if localfile
539
	retrbinary("RETR " + remotefile.to_s, blocksize, rest_offset) do |data|
540
	  f.write(data) if localfile
541
	  yield(data) if block_given?
570
        f.binmode if localfile
571
        retrbinary("RETR " + remotefile.to_s, blocksize, rest_offset) do |data|
572
          f.write(data) if localfile
573
          yield(data) if block_given?
542 574
          result.concat(data) if result
543
	end
575
        end
544 576
        return result
545 577
      ensure
546
	f.close if localfile
578
        f.close if localfile
547 579
      end
548 580
    end
549 581

  
......
562 594
        result = ""
563 595
      end
564 596
      begin
565
	retrlines("RETR " + remotefile) do |line, newline|
597
        retrlines("RETR " + remotefile) do |line, newline|
566 598
          l = newline ? line + "\n" : line
567
	  f.print(l) if localfile
568
	  yield(line, newline) if block_given?
599
          f.print(l) if localfile
600
          yield(line, newline) if block_given?
569 601
          result.concat(l) if result
570
	end
602
        end
571 603
        return result
572 604
      ensure
573
	f.close if localfile
605
        f.close if localfile
574 606
      end
575 607
    end
576 608

  
......
579 611
    # binary).  See #gettextfile and #getbinaryfile.
580 612
    #
581 613
    def get(remotefile, localfile = File.basename(remotefile),
582
	    blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data
614
            blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data
583 615
      if @binary
584
	getbinaryfile(remotefile, localfile, blocksize, &block)
616
        getbinaryfile(remotefile, localfile, blocksize, &block)
585 617
      else
586
	gettextfile(remotefile, localfile, &block)
618
        gettextfile(remotefile, localfile, &block)
587 619
      end
588 620
    end
589 621

  
......
593 625
    # data in +blocksize+ chunks.
594 626
    #
595 627
    def putbinaryfile(localfile, remotefile = File.basename(localfile),
596
		      blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data
628
                      blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data
597 629
      if @resume
598 630
        begin
599 631
          rest_offset = size(remotefile)
......
601 633
          rest_offset = nil
602 634
        end
603 635
      else
604
	rest_offset = nil
636
        rest_offset = nil
605 637
      end
606 638
      f = open(localfile)
607 639
      begin
608
	f.binmode
640
        f.binmode
609 641
        if rest_offset
610 642
          storbinary("APPE " + remotefile, f, blocksize, rest_offset, &block)
611 643
        else
612 644
          storbinary("STOR " + remotefile, f, blocksize, rest_offset, &block)
613 645
        end
614 646
      ensure
615
	f.close
647
        f.close
616 648
      end
617 649
    end
618 650

  
......
624 656
    def puttextfile(localfile, remotefile = File.basename(localfile), &block) # :yield: line
625 657
      f = open(localfile)
626 658
      begin
627
	storlines("STOR " + remotefile, f, &block)
659
        storlines("STOR " + remotefile, f, &block)
628 660
      ensure
629
	f.close
661
        f.close
630 662
      end
631 663
    end
632 664

  
......
635 667
    # (text or binary).  See #puttextfile and #putbinaryfile.
636 668
    #
637 669
    def put(localfile, remotefile = File.basename(localfile),
638
	    blocksize = DEFAULT_BLOCKSIZE, &block)
670
            blocksize = DEFAULT_BLOCKSIZE, &block)
639 671
      if @binary
640
	putbinaryfile(localfile, remotefile, blocksize, &block)
672
        putbinaryfile(localfile, remotefile, blocksize, &block)
641 673
      else
642
	puttextfile(localfile, remotefile, &block)
674
        puttextfile(localfile, remotefile, &block)
643 675
      end
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
......
657 692
    def nlst(dir = nil)
658 693
      cmd = "NLST"
659 694
      if dir
660
	cmd = cmd + " " + dir
695
        cmd = cmd + " " + dir
661 696
      end
662 697
      files = []
663 698
      retrlines(cmd) do |line|
664
	files.push(line)
699
        files.push(line)
665 700
      end
666 701
      return files
667 702
    end
......
673 708
    def list(*args, &block) # :yield: line
674 709
      cmd = "LIST"
675 710
      args.each do |arg|
676
	cmd = cmd + " " + arg.to_s
711
        cmd = cmd + " " + arg.to_s
677 712
      end
678 713
      if block
679
	retrlines(cmd, &block)
714
        retrlines(cmd, &block)
680 715
      else
681
	lines = []
682
	retrlines(cmd) do |line|
683
	  lines << line
684
	end
685
	return lines
716
        lines = []
717
        retrlines(cmd) do |line|
718
          lines << line
719
        end
720
        return lines
686 721
      end
687 722
    end
688 723
    alias ls list
......
694 729
    def rename(fromname, toname)
695 730
      resp = sendcmd("RNFR " + fromname)
696 731
      if resp[0] != ?3
697
	raise FTPReplyError, resp
732
        raise FTPReplyError, resp
698 733
      end
699 734
      voidcmd("RNTO " + toname)
700 735
    end
......
705 740
    def delete(filename)
706 741
      resp = sendcmd("DELE " + filename)
707 742
      if resp[0, 3] == "250"
708
	return
743
        return
709 744
      elsif resp[0] == ?5
710
	raise FTPPermError, resp
745
        raise FTPPermError, resp
711 746
      else
712
	raise FTPReplyError, resp
747
        raise FTPReplyError, resp
713 748
      end
714 749
    end
715 750

  
......
718 753
    #
719 754
    def chdir(dirname)
720 755
      if dirname == ".."
721
	begin
722
	  voidcmd("CDUP")
723
	  return
724
	rescue FTPPermError => e
725
	  if e.message[0, 3] != "500"
726
	    raise e
727
	  end
728
	end
756
        begin
757
          voidcmd("CDUP")
758
          return
759
        rescue FTPPermError => e
760
          if e.message[0, 3] != "500"
761
            raise e
762
          end
763
        end
729 764
      end
730 765
      cmd = "CWD " + dirname
731 766
      voidcmd(cmd)
......
786 821
    def system
787 822
      resp = sendcmd("SYST")
788 823
      if resp[0, 3] != "215"
789
	raise FTPReplyError, resp
824
        raise FTPReplyError, resp
790 825
      end
791 826
      return resp[4 .. -1]
792 827
    end
......
800 835
      @sock.send(line, Socket::MSG_OOB)
801 836
      resp = getmultiline
802 837
      unless ["426", "226", "225"].include?(resp[0, 3])
803
	raise FTPProtoError, resp
838
        raise FTPProtoError, resp
804 839
      end
805 840
      return resp
806 841
    end
......
821 856
    def mdtm(filename)
822 857
      resp = sendcmd("MDTM " + filename)
823 858
      if resp[0, 3] == "213"
824
	return resp[3 .. -1].strip
859
        return resp[3 .. -1].strip
825 860
      end
826 861
    end
827 862

  
......
831 866
    def help(arg = nil)
832 867
      cmd = "HELP"
833 868
      if arg
834
	cmd = cmd + " " + arg
869
        cmd = cmd + " " + arg
835 870
      end
836 871
      sendcmd(cmd)
837 872
    end
......
845 880

  
846 881
    #
847 882
    # Issues a NOOP command.
883
    # 
884
    # Does nothing except return a response.
848 885
    #
849 886
    def noop
850 887
      voidcmd("NOOP")
......
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
	raise FTPReplyError, resp
919
        raise FTPReplyError, resp
879 920
      end
880 921
      left = resp.index("(")
881 922
      right = resp.index(")")
882 923
      if left == nil or right == nil
883
	raise FTPProtoError, resp
924
        raise FTPProtoError, resp
884 925
      end
885 926
      numbers = resp[left + 1 .. right - 1].split(",")
886 927
      if numbers.length != 6
887
	raise FTPProtoError, resp
928
        raise FTPProtoError, resp
888 929
      end
889 930
      host = numbers[0, 4].join(".")
890 931
      port = (numbers[4].to_i << 8) + numbers[5].to_i
......
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
	raise FTPReplyError, resp
942
        raise FTPReplyError, resp
898 943
      end
899 944
      left = resp.index("(")
900 945
      right = resp.index(")")
901 946
      if left == nil or right == nil
902
	raise FTPProtoError, resp
947
        raise FTPProtoError, resp
903 948
      end
904 949
      numbers = resp[left + 1 .. right - 1].split(",")
905 950
      if numbers[0] == "4"
906
	if numbers.length != 9 || numbers[1] != "4" || numbers[2 + 4] != "2"
907
	  raise FTPProtoError, resp
908
	end
909
	host = numbers[2, 4].join(".")
910
	port = (numbers[7].to_i << 8) + numbers[8].to_i
951
        if numbers.length != 9 || numbers[1] != "4" || numbers[2 + 4] != "2"
952
          raise FTPProtoError, resp
953
        end
954
        host = numbers[2, 4].join(".")
955
        port = (numbers[7].to_i << 8) + numbers[8].to_i
911 956
      elsif numbers[0] == "6"
912
	if numbers.length != 21 || numbers[1] != "16" || numbers[2 + 16] != "2"
913
	  raise FTPProtoError, resp
914
	end
915
	v6 = ["", "", "", "", "", "", "", ""]
916
	for i in 0 .. 7
917
	  v6[i] = sprintf("%02x%02x", numbers[(i * 2) + 2].to_i,
918
			  numbers[(i * 2) + 3].to_i)
919
	end
920
	host = v6[0, 8].join(":")
921
	port = (numbers[19].to_i << 8) + numbers[20].to_i
957
        if numbers.length != 21 || numbers[1] != "16" || numbers[2 + 16] != "2"
958
          raise FTPProtoError, resp
959
        end
960
        v6 = ["", "", "", "", "", "", "", ""]
961
        for i in 0 .. 7
962
          v6[i] = sprintf("%02x%02x", numbers[(i * 2) + 2].to_i,
963
                          numbers[(i * 2) + 3].to_i)
964
        end
965
        host = v6[0, 8].join(":")
966
        port = (numbers[19].to_i << 8) + numbers[20].to_i
922 967
      end
923 968
      return host, port
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
	raise FTPReplyError, resp
978
        raise FTPReplyError, resp
930 979
      end
931 980
      left = resp.index("(")
932 981
      right = resp.index(")")
933 982
      if left == nil or right == nil
934
	raise FTPProtoError, resp
983
        raise FTPProtoError, resp
935 984
      end
936 985
      numbers = resp[left + 1 .. right - 1].split(resp[left + 1, 1])
937 986
      if numbers.length != 4
938
	raise FTPProtoError, resp
987
        raise FTPProtoError, resp
939 988
      end
940 989
      port = numbers[3].to_i
941 990
      host = (@sock.peeraddr())[3]
......
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
	raise FTPReplyError, resp
1001
        raise FTPReplyError, resp
949 1002
      end
950 1003
      if resp[3, 2] != ' "'
951
	return ""
1004
        return ""
952 1005
      end
953 1006
      dirname = ""
954 1007
      i = 5
955 1008
      n = resp.length
956 1009
      while i < n
957
	c = resp[i, 1]
958
	i = i + 1
959
	if c == '"'
960
	  if i > n or resp[i, 1] != '"'
961
	    break
962
	  end
963
	  i = i + 1
964
	end
965
	dirname = dirname + c
1010
        c = resp[i, 1]
1011
        i = i + 1
1012
        if c == '"'
1013
          if i > n or resp[i, 1] != '"'
1014
            break
1015
          end
1016
          i = i + 1
1017
        end
1018
        dirname = dirname + c
966 1019
      end
967 1020
      return dirname
968 1021
    end