Open File Remotely

I know that this question looks like a Webistrano question but since I
don’t know much about Ruby, I thought it might be a simple Ruby question
too.
We have installed Webistrano and Capistrano install on some server
(let’s say Server1). I have created a Webistrano project and inside it I
have defined my Host to be ‘Server2’. I have this Ruby code inside my
project:
require ‘open-uri’
writeout = open("/home/test/test.txt", “wb”)
writeout.write(“TEST”)
writeout.close

The problem is Webistrano is giving me an error saying that
/home/test/test.txt does not exist. I believe what It’s trying to do is
to create test.txt in Server1 (Capistrano Server) instead of my defined
Host.
Is there any way in Ruby to say Open the file remotely (e.g.
“Server2:/home/test/test.txt”) (assuming there is no Server of any kind
installed on Server2).
Strange is if I have a command like run “bash --login -c ‘touch
test.txt’”, it will create test.txt in the right defined Host (Server2).
But ‘open’ somehow is failing.

Thanks in Advance,

Homer

Is there any way in Ruby to say Open the file remotely (e.g.
“Server2:/home/test/test.txt”) (assuming there is no Server of any kind
installed on Server2).

I doubt it. You could try farming out to ssh, though…

On 11/12/09, Homer N. [email protected] wrote:

Is there any way in Ruby to say Open the file remotely (e.g.
“Server2:/home/test/test.txt”) (assuming there is no Server of any kind
installed on Server2).

Try open-uri, maybe? It’s in the standard lib.

On Thursday 12 November 2009 09:30:14 am Homer N. wrote:

Is there any way in Ruby to say Open the file remotely (e.g.
“Server2:/home/test/test.txt”) (assuming there is no Server of any kind
installed on Server2).

Short answer: No. That’s really not a Ruby question, either – would you
expect that to work in any language?

Strange is if I have a command like run “bash --login -c ‘touch
test.txt’”, it will create test.txt in the right defined Host (Server2).
But ‘open’ somehow is failing.

Ah, now this is a Capistrano question. FYI, there is a Capistrano group.

First, how are you running this command? Ruby has two main ways of
running
commands: system and backticks. It seems you’re doing neither of these,
but
rather, “run”, which is a Capistrano command.

Run sends that command over to the remote server, over the ssh
connection, to
run there.

Ruby code in Cap, however, runs locally. Try running the same command
with
“system” and see what happens.

If all you’re wanting to do is programmatically generate a file as you
upload
it, I seem to remember some Capistrano recipes for that. It’s been
awhile,
though, and I’m feeling lazy, so ask the Capistrano group.

On Monday 16 November 2009 09:06:55 am Homer N. wrote:

Thanks All. Finally I’ve found an easier way to fix this problem. I SSH
to the box and do WGET to get the remote file. I am not sure this is the
best way but it seems working.

It’s not that far from how Capistrano was originally designed to work,
with
one problem: You’re probably not doing any kind of authentication with
that
wget, which is probably a Bad Idea. That’s why I usually send things via
“put”
with Capistrano – you’ve already got an encrypted, authenticated
channel with
SSH, why not use it?

I guess I need to learn some
Ruby/Capistrano in meanwhile.

Also, don’t top-post.

Thanks All. Finally I’ve found an easier way to fix this problem. I SSH
to the box and do WGET to get the remote file. I am not sure this is the
best way but it seems working. I guess I need to learn some
Ruby/Capistrano in meanwhile.

Homer

David M. wrote:

On Thursday 12 November 2009 09:30:14 am Homer N. wrote:

Is there any way in Ruby to say Open the file remotely (e.g.
“Server2:/home/test/test.txt”) (assuming there is no Server of any kind
installed on Server2).

Short answer: No. That’s really not a Ruby question, either – would you
expect that to work in any language?

Strange is if I have a command like run “bash --login -c ‘touch
test.txt’”, it will create test.txt in the right defined Host (Server2).
But ‘open’ somehow is failing.

Ah, now this is a Capistrano question. FYI, there is a Capistrano group.

First, how are you running this command? Ruby has two main ways of
running
commands: system and backticks. It seems you’re doing neither of these,
but
rather, “run”, which is a Capistrano command.

Run sends that command over to the remote server, over the ssh
connection, to
run there.

Ruby code in Cap, however, runs locally. Try running the same command
with
“system” and see what happens.

If all you’re wanting to do is programmatically generate a file as you
upload
it, I seem to remember some Capistrano recipes for that. It’s been
awhile,
though, and I’m feeling lazy, so ask the Capistrano group.