downloading a file

Discussion in 'Ruby' started by Rajinder Yadav, Dec 20, 2010.

  1. hello what is the best way to download a file?

    if the process get interrupted like the network goes down for a little
    while, is there a way to continue the download from the point it left off?

    I am seeking various solutions, thanks!

    --
    Kind Regards,
    Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely

    GNU/Linux: 2.6.35-23-generic
    Kubuntu x86_64 10.10 | KDE 4.5.1
    Ruby 1.9.2p0 | Rails 3.0.3
    Rajinder Yadav, Dec 20, 2010
    #1
    1. Advertising

  2. Rajinder Yadav

    zuerrong Guest

    2010/12/20 Rajinder Yadav <>:
    > hello what is the best way to download a file?
    >
    > if the process get interrupted like the network goes down for a little
    > while, is there a way to continue the download from the point it left off?


    what protocal shall be used?
    consider:

    Net::HTTP
    Net::FTP
    zuerrong, Dec 20, 2010
    #2
    1. Advertising

  3. Rajinder Yadav wrote in post #969503:
    > hello what is the best way to download a file?
    >
    > if the process get interrupted like the network goes down for a little
    > while, is there a way to continue the download from the point it left
    > off?


    Use wget [-c]

    --
    Posted via http://www.ruby-forum.com/.
    Brian Candler, Dec 20, 2010
    #3
  4. On Mon, Dec 20, 2010 at 6:11 AM, Brian Candler <> wrote:
    > Rajinder Yadav wrote in post #969503:
    >> hello what is the best way to download a file?
    >>
    >> if the process get interrupted like the network goes down for a little
    >> while, is there a way to continue the download from the point it left
    >> off?

    >
    > Use wget [-c]


    ruby has a wget command? i want to do this from ruby code, and with no
    backquote either

    --
    Kind Regards,
    Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely

    GNU/Linux: 2.6.35-22-generic
    Kubuntu x86_64 10.10 | KDE 4.5.1
    Ruby 1.9.2p0 | Rails 3.0.1
    Rajinder Yadav, Dec 20, 2010
    #4
  5. Rajinder Yadav wrote in post #969592:
    >> Use wget [-c]

    >
    > ruby has a wget command? i want to do this from ruby code, and with no
    > backquote either


    I was thinking of:

    system("wget ....")

    If you don't have wget on your system, I'm afraid I don't know of an
    existing Ruby library which does download-to-file with restarting of
    partial transfers.

    You can cobble something together using Net::HTTP, but to do the
    restarts you'll have to use the set_range method to add the Range:
    header - see RFC 2616 section 14.35.

    Note that old HTTP servers may ignore the Range: header, so you should
    check that the response content_range is what you asked for.

    --
    Posted via http://www.ruby-forum.com/.
    Brian Candler, Dec 20, 2010
    #5
  6. On Mon, Dec 20, 2010 at 1:10 PM, Brian Candler <> wrote:
    > Rajinder Yadav wrote in post #969592:
    >>> Use wget [-c]

    >>
    >> ruby has a wget command? i want to do this from ruby code, and with no
    >> backquote either

    >
    > I was thinking of:
    >
    > =A0 =A0system("wget ....")
    >
    > If you don't have wget on your system, I'm afraid I don't know of an
    > existing Ruby library which does download-to-file with restarting of
    > partial transfers.
    >
    > You can cobble something together using Net::HTTP, but to do the
    > restarts you'll have to use the set_range method to add the Range:
    > header - see RFC 2616 section 14.35.
    >
    > Note that old HTTP servers may ignore the Range: header, so you should
    > check that the response content_range is what you asked for.


    well if i just want to download a file, is there something i can use
    that is simple?

    i tired using open-uri, but when i read and then save the file it mess
    up the file? something like this

    require 'open-uri'
    url =3D 'http://www.openssl.org/source/openssl-1.0.0c.tar.gz'
    file =3D open(url)
    c =3D file.read

    f =3D File.open('openssl-1.0.0c.tar.gz', 'w')
    f.write c
    f.close


    --=20
    Kind Regards,
    Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely

    GNU/Linux: 2.6.35-22-generic
    Kubuntu x86_64 10.10 | KDE 4.5.1
    Ruby 1.9.2p0 | Rails 3.0.1
    Rajinder Yadav, Dec 20, 2010
    #6
  7. On Mon, Dec 20, 2010 at 1:19 PM, Rajinder Yadav <> wrote=
    :
    > On Mon, Dec 20, 2010 at 1:10 PM, Brian Candler <> wrot=

    e:
    >> Rajinder Yadav wrote in post #969592:
    >>>> Use wget [-c]
    >>>
    >>> ruby has a wget command? i want to do this from ruby code, and with no
    >>> backquote either

    >>
    >> I was thinking of:
    >>
    >> =A0 =A0system("wget ....")
    >>
    >> If you don't have wget on your system, I'm afraid I don't know of an
    >> existing Ruby library which does download-to-file with restarting of
    >> partial transfers.
    >>
    >> You can cobble something together using Net::HTTP, but to do the
    >> restarts you'll have to use the set_range method to add the Range:
    >> header - see RFC 2616 section 14.35.
    >>
    >> Note that old HTTP servers may ignore the Range: header, so you should
    >> check that the response content_range is what you asked for.

    >
    > well if i just want to download a file, is there something i can use
    > that is simple?
    >
    > i tired using open-uri, but when i read and then save the file it mess
    > up the file? something like this
    >
    > require 'open-uri'
    > url =3D 'http://www.openssl.org/source/openssl-1.0.0c.tar.gz'
    > file =3D open(url)
    > c =3D file.read
    >
    > f =3D File.open('openssl-1.0.0c.tar.gz', 'w')
    > f.write c
    > f.close
    >


    i'm wondering if there is libcurl solution out there that will
    download files, both binary and text?

    --=20
    Kind Regards,
    Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely

    GNU/Linux: 2.6.35-22-generic
    Kubuntu x86_64 10.10 | KDE 4.5.1
    Ruby 1.9.2p0 | Rails 3.0.1
    Rajinder Yadav, Dec 20, 2010
    #7
  8. [Note: parts of this message were removed to make it a legal post.]

    Good Morning


    > i'm wondering if there is libcurl solution out there that will
    > download files, both binary and text?
    >


    I'm sure you might have heard of this great new website that was created 12+
    years ago - GOOGLE. At that very website if someone like yourself entered -
    ruby download file - you might find these things called websites that
    actually contain information pertaining to the exact subject you asked
    Google about.

    John

    P.S. Just for fun you may also wish to get wacky and try - ruby libcurl -
    who knows what those 11 letters will find for you......
    John W Higgins, Dec 20, 2010
    #8
  9. On Mon, Dec 20, 2010 at 1:42 PM, John W Higgins <> wrote:
    > Good Morning
    >
    >
    >> i'm wondering if there is libcurl solution out there that will
    >> download files, both binary and text?
    >>

    >
    > I'm sure you might have heard of this great new website that was created 12+
    > years ago - GOOGLE. At that very website if someone like yourself entered -
    > ruby download file - you might find these things called websites that
    > actually contain information pertaining to the exact subject you asked
    > Google about.
    >
    > John
    >
    > P.S. Just for fun you may also wish to get wacky and try - ruby libcurl -
    > who knows what those 11 letters will find for you......
    >


    WOW IS TODAY ASSHOLE DAY, I MISSED THE MEMO????


    --
    Kind Regards,
    Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely

    GNU/Linux: 2.6.35-22-generic
    Kubuntu x86_64 10.10 | KDE 4.5.1
    Ruby 1.9.2p0 | Rails 3.0.1
    Rajinder Yadav, Dec 20, 2010
    #9
  10. Rajinder Yadav

    Quintus Guest

    Am 20.12.2010 19:19, schrieb Rajinder Yadav:
    > i tired using open-uri, but when i read and then save the file it mess
    > up the file? something like this
    >
    > require 'open-uri'
    > url = 'http://www.openssl.org/source/openssl-1.0.0c.tar.gz'
    > file = open(url)
    > c = file.read
    >
    > f = File.open('openssl-1.0.0c.tar.gz', 'w')
    > f.write c
    > f.close


    Try

    file = open(url, "rb")

    instead of

    file = open(url)

    and

    f = File.open('openssl-1.0.0c.tar.gz', 'wb')

    instead of

    f = File.open('openssl-1.0.0c.tar.gz', 'w')

    You're downloading a binary file, and Ruby will do bad things to
    newlines in it if you don't pass the "b" for binary.
    Additionally you should have a look at the block form of #open.

    Vale,
    Marvin
    Quintus, Dec 20, 2010
    #10
  11. On Mon, Dec 20, 2010 at 2:43 PM, Quintus <> wrote:
    > Am 20.12.2010 19:19, schrieb Rajinder Yadav:
    >> i tired using open-uri, but when i read and then save the file it mess
    >> up the file? something like this
    >>
    >> require 'open-uri'
    >> url = 'http://www.openssl.org/source/openssl-1.0.0c.tar.gz'
    >> file = open(url)
    >> c = file.read
    >>
    >> f = File.open('openssl-1.0.0c.tar.gz', 'w')
    >> f.write c
    >> f.close

    >
    > Try
    >
    > file = open(url, "rb")
    >
    > instead of
    >
    > file = open(url)
    >
    > and
    >
    > f = File.open('openssl-1.0.0c.tar.gz', 'wb')
    >
    > instead of
    >
    > f = File.open('openssl-1.0.0c.tar.gz', 'w')
    >
    > . You're downloading a binary file, and Ruby will do bad things to
    > newlines in it if you don't pass the "b" for binary.
    > Additionally you should have a look at the block form of #open.
    >
    > Vale,
    > Marvin
    >
    >


    Thanks Vale,

    that makes sense, i also just found out I can use context_type() to
    figure out the file type!

    --
    Kind Regards,
    Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely

    GNU/Linux: 2.6.35-22-generic
    Kubuntu x86_64 10.10 | KDE 4.5.1
    Ruby 1.9.2p0 | Rails 3.0.1
    Rajinder Yadav, Dec 20, 2010
    #11
  12. On Mon, Dec 20, 2010 at 2:58 PM, Rajinder Yadav <> wrote:
    > On Mon, Dec 20, 2010 at 2:43 PM, Quintus <> wrote:
    >> Am 20.12.2010 19:19, schrieb Rajinder Yadav:
    >>> i tired using open-uri, but when i read and then save the file it mess
    >>> up the file? something like this
    >>>
    >>> require 'open-uri'
    >>> url = 'http://www.openssl.org/source/openssl-1.0.0c.tar.gz'
    >>> file = open(url)
    >>> c = file.read
    >>>
    >>> f = File.open('openssl-1.0.0c.tar.gz', 'w')
    >>> f.write c
    >>> f.close

    >>
    >> Try
    >>
    >> file = open(url, "rb")
    >>
    >> instead of
    >>
    >> file = open(url)
    >>
    >> and
    >>
    >> f = File.open('openssl-1.0.0c.tar.gz', 'wb')
    >>
    >> instead of
    >>
    >> f = File.open('openssl-1.0.0c.tar.gz', 'w')
    >>
    >> . You're downloading a binary file, and Ruby will do bad things to
    >> newlines in it if you don't pass the "b" for binary.
    >> Additionally you should have a look at the block form of #open.
    >>
    >> Vale,
    >> Marvin
    >>
    >>

    >
    > Thanks Vale,
    >
    > that makes sense, i also just found out I can use context_type() to
    > figure out the file type!
    >


    Thanks Marvin, tired eyes got the name wrong =)

    --
    Kind Regards,
    Rajinder Yadav
    Rajinder Yadav, Dec 20, 2010
    #12
    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. Ian Gordon

    Downloading a file...

    Ian Gordon, Jul 30, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    939
    Ian Gordon
    Jul 30, 2003
  2. Chris Morrison

    Downloading a file from a website

    Chris Morrison, Dec 18, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    507
    Vijayakrishna Pondala
    Dec 31, 2003
  3. Replies:
    0
    Views:
    405
  4. Steven

    Downloading a file

    Steven, Jul 28, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    388
    Joerg Jooss
    Aug 2, 2003
  5. Ian Gordon

    Downloading a file to client

    Ian Gordon, Jul 30, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    353
    Bill Priess
    Jul 30, 2003
Loading...

Share This Page