Net::SSH::SFTP::Simple fails to get file

greetings to all
following code fails to retrieve file from server
the script completes with no errors produced

···

-----------------------------------

#!/usr/local/bin/ruby

require 'net/ssh'
require 'net/ssh/sftp/attrs'
require 'net/ssh/sftp/constants'
require 'net/ssh/sftp/session'
require 'net/ssh/transport/buffer'
require 'net/ssh/sftp/simple'

Net::SSH::SFTP::Simple.new( 'www.fobar.com', 'foo', 'pass1234' ) do

sftp>

        status, files = sftp.list_dir( "/backups" )
        status, body = sftp.get( "/foo/foo.tar.bz2" )
end

------------------------------

hackerotaku wrote:

greetings to all
following code fails to retrieve file from server
the script completes with no errors produced

-----------------------------------

#!/usr/local/bin/ruby

require 'net/ssh'
require 'net/ssh/sftp/attrs'
require 'net/ssh/sftp/constants'
require 'net/ssh/sftp/session'
require 'net/ssh/transport/buffer'
require 'net/ssh/sftp/simple'

Net::SSH::SFTP::Simple.new( 'www.fobar.com', 'foo', 'pass1234' ) do
>sftp>
        status, files = sftp.list_dir( "/backups" )
        status, body = sftp.get( "/foo/foo.tar.bz2" )
end

How are you testing to see if no file is retrieved? The "get" method doesn't store a file on the local host -- it only grabs the contents of the file and returns it as "body". If you want the file copied from the remote host and then stored on the local host, you should either explicitly open the local file and write to it, _or_ you can use the "get_file" method.

Let me know if that works for you. More work remains to be done with the SFTP protocol in Net::SSH, but the existing features work okay for me...

···

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck.org/jamis

"I use octal until I get to 8, and then I switch to decimal."

Jamis,

thank you
i am working on using the
sftp.get_file method

excellent

:wink:

justin
keep up the excellent work

:slight_smile:

Jamis,

good news
this works
below code will put a file on the remote system
and it will get a file from the remote syste
thank you

···

------------------------------------------------------------
#!/usr/bin/ruby

require 'net/ssh'
require 'net/ssh/sftp/attrs'
require 'net/ssh/sftp/constants'
require 'net/ssh/sftp/session'
require 'net/ssh/transport/buffer'
require 'net/ssh/sftp/simple'

Net::SSH::SFTP::Simple.new( "www.foobar.com", "foo", "password" ) do

sftp>

         status, files = sftp.list_dir( "/FOO/tester" )
         status, body = sftp.get_file( "/FOO/tester/alpha", "alpha" )
end

Net::SSH::SFTP::Simple.new("www.foobar.com", "foobar", "password") do

sftp>

  status, files = sftp.list_dir( "/FOO/tester" )
  status, body = sftp.put_file( "ALPHA.TXT", "/FOO/tester/tango" )
end

-----------------------------------------------------------

Jamis,

good news
this works
below code will put a file on the remote system
and it will get a file from the remote syste
thank you

···

------------------------------------------------------------
#!/usr/bin/ruby

require 'net/ssh'
require 'net/ssh/sftp/attrs'
require 'net/ssh/sftp/constants'
require 'net/ssh/sftp/session'
require 'net/ssh/transport/buffer'
require 'net/ssh/sftp/simple'

Net::SSH::SFTP::Simple.new( "www.foobar.com", "foo", "password" ) do

sftp>

         status, files = sftp.list_dir( "/FOO/tester" )
         status, body = sftp.get_file( "/FOO/tester/alpha", "alpha" )
end

Net::SSH::SFTP::Simple.new("www.foobar.com", "foobar", "password") do

sftp>

  status, files = sftp.list_dir( "/FOO/tester" )
  status, body = sftp.put_file( "ALPHA.TXT", "/FOO/tester/tango" )
end

-----------------------------------------------------------

hackerotaku wrote:

Jamis,

good news this works
below code will put a file on the remote system
and it will get a file from the remote syste
thank you

Glad to hear it! I'm just about ready to start documenting the SFTP features of Net::SSH, so hopefully that will prevent others from the frustrations you encountered.

- Jamis

···

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck.org/jamis

"I use octal until I get to 8, and then I switch to decimal."