On Tue, Apr 7, 2009 at 10:27 PM, Shripad <shripad.josh...@gmail.com> wrote:

>
> Hi all,
>
> I am having following code in ruby
>
> require 'net/ssh'
>  require 'net/sftp'
>  begin
>    Net::SSH.start
> ('132.147.161.159',:password=>'k',:port=>1234,:username=>'k') do |ssh|
>      ssh.sftp.connect do |sftp|
>        Dir.foreach('.') do |file|
>            puts file
>        end
>    end
> end
> rescue Exception=> Ex
> puts Ex.message
> end
>
> After executing the above code it is giving me following error
>
> Bad file descriptor - connect(2)
>
> username, password, and ipaddress are fine
>
> What I want is to take data from remote machine to server.
>
> Please Help me out.
>
>
> Thanks and Regards,
> Shri


What are you wanting to do?  SFTP or SSH?  From the code,
it appears that you're trying to move a file from point A to B.
Thus, here's a brief outline of the things that you can do with
SFTP:

require 'net/sftp'

  Net::SFTP.start('host', 'username', :password => 'password') do |sftp|
    # upload a file or directory to the remote host
    sftp.upload!("/path/to/local", "/path/to/remote")

    # download a file or directory from the remote host
    sftp.download!("/path/to/remote", "/path/to/local")

    # grab data off the remote host directly to a buffer
    data = sftp.download!("/path/to/remote")

    # open and write to a pseudo-IO for a remote file
    sftp.file.open("/path/to/remote", "w") do |f|
      f.puts "Hello, world!\n"
    end

    # open and read from a pseudo-IO for a remote file
    sftp.file.open("/path/to/remote", "r") do |f|
      puts f.gets
    end

    # create a directory
    sftp.mkdir! "/path/to/directory"

    # list the entries in a directory
    sftp.dir.foreach("/path/to/directory") do |entry|
      puts entry.longname
    end
  end

Good luck,


-Conrad



>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to