Forum: Ruby on Rails Using Net::SFTP from within Rails models

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ff43001ac5fe9805aa6ca2e89d3b7b5d?d=identicon&s=25 Jake Janovetz (janovetz)
on 2007-02-13 06:56
Hello --

Is there some trick to using Net::SFTP within a Rails model?  I keep
getting the following error and for the life of me I can't figure it
out.  The code works fine outside the model context (i.e. in a ruby
console):

c:/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel/debug.rb:121:in
`orig_open'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel/debug.rb:121:in
`open'
c:/ruby/lib/ruby/gems/1.8/gems/net-sftp-1.1.0/lib/net/sftp/operations/open.rb:27:in
`perform'
c:/ruby/lib/ruby/gems/1.8/gems/net-sftp-1.1.0/lib/net/sftp/operations/abstract.rb:64:in
`execute'
c:/ruby/lib/ruby/gems/1.8/gems/net-sftp-1.1.0/lib/net/sftp/session.rb:253:in
`method_missing'
c:/ruby/lib/ruby/gems/1.8/gems/net-sftp-1.1.0/lib/net/sftp/session.rb:177:in
`open_handle'
c:/ruby/lib/ruby/gems/1.8/gems/net-sftp-1.1.0/lib/net/sftp/session.rb:203:in
`put_file'


The code is just:

  Net::SFTP.start(@sftp_server, @sftp_login, @sftp_password) do |sftp|
    sftp.put_file self.path, "/home/blah-blah/dir"
  end


   Cheers,
   Jake
6d3c187a8b3ef53b08e3e7e8572c4fea?d=identicon&s=25 Jeremy McAnally (Guest)
on 2007-02-13 07:17
(Received via mailing list)
You didn't really give us the error...just the stack trace. :)  Can
you tell us exactly what exception is being thrown?

--Jeremy

On 2/13/07, Jake Janovetz <rails-mailing-list@andreas-s.net> wrote:
> c:/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel/debug.rb:121:in
> `put_file'
>    Jake
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>


--
http://www.jeremymcanally.com/

My free Ruby e-book:
http://www.humblelittlerubybook.com/book/

My blogs:
http://www.mrneighborly.com/
http://www.rubyinpractice.com/
Ff43001ac5fe9805aa6ca2e89d3b7b5d?d=identicon&s=25 Jake Janovetz (janovetz)
on 2007-02-13 07:21
Oops.  It's just:

can't convert nil into String

But it's not from any of my stuff being 'nil'.  The trace comes down to
these lines in Net::SFTP::open.rb:
---
    # Performs the operation.
    def perform( path, flags=IO::RDONLY, mode=0660 )
      @driver.open( nil, path, flags, mode )
    end
---

I'm guessing it's that first nil there, but I'm having some trouble
figuring out what's going on.

   Jake



Jeremy McAnally wrote:
> You didn't really give us the error...just the stack trace. :)  Can
> you tell us exactly what exception is being thrown?
>
> --Jeremy
>
> On 2/13/07, Jake Janovetz <rails-mailing-list@andreas-s.net> wrote:
>> c:/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel/debug.rb:121:in
>> `put_file'
>>    Jake
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>> >
>>
>
>
> --
> http://www.jeremymcanally.com/
>
> My free Ruby e-book:
> http://www.humblelittlerubybook.com/book/
>
> My blogs:
> http://www.mrneighborly.com/
> http://www.rubyinpractice.com/
This topic is locked and can not be replied to.