@sock.readline no response in ftp.rb

Discussion in 'Ruby' started by Fengfeng Li, May 3, 2011.

  1. Fengfeng Li

    Fengfeng Li Guest

    Hi everyone,

    I'm using ruby 1.8.7 p334 on windows.

    My code below is really simple, but there's something wrong if the ftp
    lasts for a long time:

    #code begin
    require 'net/ftp'
    require 'time'

    ftp = Net::FTP.new("189.41.6.136")
    ftp.login("mlog_123_usr", "MLog_123_pwd")
    puts Time.now()
    puts ftp.list
    ftp.putbinaryfile("D:\\version\\XXX.cc") # here
    puts Time.now()
    ftp.close
    #code end

    My destination host is very slow, so uploading a file(about 5M) can take
    about 15 minutes, then ruby.exe cann't exit forever(I see from the host
    to make sure the file has been uploaded and there's no existing
    ftp-users)!

    If the uploading can be finished in a few seconds, everything is OK.

    I've tried both the 1.8.6&1.8.7 version, they behaved the same way.

    I traced the raw codes in ftp.rb, and found it was stopped when
    @sock.readline.

    #ruby code
    def getline
    line = @sock.readline # if get EOF, raise EOFError
    line.sub!(/(\r\n|\n|\r)\z/n, "")
    if @debug_mode
    print "get: ", sanitize(line), "\n"
    end
    return line
    end
    private :getline
    #ruby code

    Is it because of my host not giving ruby.exe correct response, or
    because of ruby itself?

    Thanks a lot.

    --
    Posted via http://www.ruby-forum.com/.
    Fengfeng Li, May 3, 2011
    #1
    1. Advertising

  2. On Tue, May 3, 2011 at 11:25 AM, Fengfeng Li <> wrote:
    > Hi everyone,
    >
    > I'm using ruby 1.8.7 p334 on windows.
    >
    > My code below is really simple, but there's something wrong if the ftp
    > lasts for a long time:
    >
    > #code begin
    > require 'net/ftp'
    > require 'time'
    >
    > ftp =3D Net::FTP.new("189.41.6.136")
    > ftp.login("mlog_123_usr", "MLog_123_pwd")
    > puts Time.now()
    > puts ftp.list
    > ftp.putbinaryfile("D:\\version\\XXX.cc") =A0# here
    > puts Time.now()
    > ftp.close
    > #code end
    >
    > My destination host is very slow, so uploading a file(about 5M) can take
    > about 15 minutes, then ruby.exe cann't exit forever(I see from the host
    > to make sure the file has been uploaded and there's no existing
    > ftp-users)!
    >
    > If the uploading can be finished in a few seconds, everything is OK.
    >
    > I've tried both the 1.8.6&1.8.7 version, they behaved the same way.
    >
    > I traced the raw codes in ftp.rb, and found it was stopped when
    > @sock.readline.
    >
    > #ruby code
    > =A0 =A0def getline
    > =A0 =A0 =A0line =3D @sock.readline # if get EOF, raise EOFError
    > =A0 =A0 =A0line.sub!(/(\r\n|\n|\r)\z/n, "")
    > =A0 =A0 =A0if @debug_mode
    > =A0print "get: ", sanitize(line), "\n"
    > =A0 =A0 =A0end
    > =A0 =A0 =A0return line
    > =A0 =A0end
    > =A0 =A0private :getline
    > #ruby code
    >
    > Is it because of my host not giving ruby.exe correct response, or
    > because of ruby itself?


    I would assume it to be unlikely that it is a bug in Ruby's FTP
    library. Rather I would assume that you either have network trouble -
    or do not wait long enough. Did you try to debug the network with a
    network monitor (e.g. Wireshark)?

    Cheers

    robert

    --=20
    remember.guy do |as, often| as.you_can - without end
    http://blog.rubybestpractices.com/
    Robert Klemme, May 3, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gavino
    Replies:
    4
    Views:
    529
    gavino
    Sep 20, 2010
  2. D. Buck
    Replies:
    2
    Views:
    462
    D. Buck
    Jun 29, 2004
  3. Nikolaus Rath
    Replies:
    1
    Views:
    66
    Roy Smith
    Feb 17, 2014
  4. Chris Angelico
    Replies:
    0
    Views:
    66
    Chris Angelico
    Feb 17, 2014
  5. Nikolaus Rath
    Replies:
    0
    Views:
    75
    Nikolaus Rath
    Feb 18, 2014
Loading...

Share This Page