SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    get back to rowing khu19's Avatar
    Join Date
    Jan 2003
    Location
    New York / Boston
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Direct file transfer program

    Hi all,

    I want to write an app that allows two people to quickly and easily transfer files between each other (something like directIM in AIM and GAIM). The motivation behind this program is that I hate setting up a ftp server, or attaching to emails when all I want to do is send a small file.

    I've done some simple network programming here in college (basic TCP/UDP socket stuff) so I want to know if there is any more that is required for entire file transfers?

    I'm also planning to do this in ruby (since it seems to be the talk of the town). Does anyone have any experience with this sort of application (in any language really, but Ruby specifically).

    thanks
    Kevin

  2. #2
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    There's a buddy of mine who was talking about doing something similar

    A buddy of mine was talking about doing something similar to what you're talking about. I think it is pretty much as simple as what you're thinking. The only thing you would want to be wary of are firewall issues, but if the ftp solution is already working for you, then that probably isn't a problem.

    Good luck

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Yakima WA.
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It sounds like you have ruby on both ends? If so one solution would be to use webrick, a pure ruby web server that is in ruby's standard library. You can get more info here: http://www.webrick.org/. Here is an example of how easy it is to create a simple http server:


    Code:
    #!/usr/local/bin/ruby
    require 'webrick'
    include WEBrick
    
    s = HTTPServer.new(
      :Port            => 2000,
      :DocumentRoot    => Dir::pwd + "/htdocs"
    )
    
    ## mount subdirectory
    s.mount("/~username",
            HTTPServlet::FileHandler, "/home/username/public_html",
            true)  #<= allow to show directory index.
    
    trap("INT"){ s.shutdown }
    s.start
    This way you could run a webrick server on each computer and transfer files easily with curl or a web brower. Or if you want to keep it pure ruby use open-uri for the client side of the transfers. Here is an example of open-uri:

    Code:
    require 'open-uri'
    
    remote_file = open("ip_address_of_server:2000/test.tar.gz").read
    File.open("test.tar.gz", "w+") do |file|
        file.write(remote_file)
    end
    And then if you want to flesh things out a bit, the webrick servelet will give a directory listing if you don't specify a file. You could have you client get a listing of available files and ask them on the command line for the name of the file they want. Then use that filename fo rhte open-uri request and the file.write and you would have a pretty cool system~

    -Ezra

  4. #4
    get back to rowing khu19's Avatar
    Join Date
    Jan 2003
    Location
    New York / Boston
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys thanks for the tips. I'll look into. If Ruby doesn't work out, I might just do it in java...but I really dislike Swing.

  5. #5
    get back to rowing khu19's Avatar
    Join Date
    Jan 2003
    Location
    New York / Boston
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ezmobius1
    It sounds like you have ruby on both ends? If so one solution would be to use webrick, a pure ruby web server that is in ruby's standard library. You can get more info here: http://www.webrick.org/. Here is an example of how easy it is to create a simple http server:


    Code:
    #!/usr/local/bin/ruby
     require 'webrick'
     include WEBrick
     
     s = HTTPServer.new(
       :Port            => 2000,
       :DocumentRoot    => Dir::pwd + "/htdocs"
     )
     
     ## mount subdirectory
     s.mount("/~username",
             HTTPServlet::FileHandler, "/home/username/public_html",
             true)  #<= allow to show directory index.
     
     trap("INT"){ s.shutdown }
     s.start
    This way you could run a webrick server on each computer and transfer files easily with curl or a web brower. Or if you want to keep it pure ruby use open-uri for the client side of the transfers. Here is an example of open-uri:

    Code:
    require 'open-uri'
     
     remote_file = open("ip_address_of_server:2000/test.tar.gz").read
     File.open("test.tar.gz", "w+") do |file|
         file.write(remote_file)
     end

    -Ezra
    What about security? What would prevent a user from just uploading withput permission?

  6. #6
    Resident Java Hater
    Join Date
    Jul 2004
    Location
    Gerodieville Central, UK
    Posts
    446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    *Shivers at thought of Java*

    I hated Java before I got to university. Now I really detest it with a passion now I have to use it.

    Only thing I found with Webrick is there aren;t many resources on the net explaining how to use it for custom work. I guess I've just not channeled enough time into looking into it though.

  7. #7
    get back to rowing khu19's Avatar
    Join Date
    Jan 2003
    Location
    New York / Boston
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    More questions.

    How difficult is it to use WxRuby? Is it possible to make a standalone exe, which is runnable on linux and windows? Sorry for noob questions.

  8. #8
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by khu19
    More questions.

    How difficult is it to use WxRuby? Is it possible to make a standalone exe, which is runnable on linux and windows? Sorry for noob questions.

    I don't know anything about wxruby, so I can't comment on that, I have used rubytk and have found that to be an easy toolkit to learn and use, (and it has the benefit of working out of the box on both windows and linux).

    for a standalone exe look for a gem called rubyscript2exe
    this will make an exe with the ruby interpreter packeged in with the script. It's not really a compiler, but it does give you a single file that you can just run as though it were an exe. I believe if you want to distribute to both linux and windows, you will have to create two seperate files with rubyscript2exe, one for linux and one for windows.

    PS, I've had more luck using rubyscript2exe on windows than linux, but I suspect this has to do with the fact I'm on unbuntu and am using the ubuntu packages which are configured strangely, if I had built ruby from scratch, I suspect this problem would disappear.

    hope this helps.

  9. #9
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Yakima WA.
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I leave that as an excercise to the user . Seriously though, you might wnat to consider using xml-rpc on both ends. Its fairly easy to do with ruby and there is some security built into that protocol. And you can send files that way to after you base64 encode them.
    But I guess I would like more information about the app you want to write before I can give much better response.

    Details please?

    -Ezra


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •