Open File Remotely

H

Homer Najafi

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
 
R

Roger Pack

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...
 
C

Caleb Clausen

Is there any way in Ruby to say Open the file remotely (e.g.
=93Server2:/home/test/test.txt=94) (assuming there is no Server of any ki= nd
installed on Server2).

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

David Masover

Is there any way in Ruby to say Open the file remotely (e.g.
=E2=80=9CServer2:/home/test/test.txt=E2=80=9D) (assuming there is no Serv= er of any kind
installed on Server2).

Short answer: No. That's really not a Ruby question, either -- would you=20
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 =E2=80=98open=E2=80=99 somehow is failing.

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

=46irst, how are you running this command? Ruby has two main ways of runnin=
g=20
commands: system and backticks. It seems you're doing neither of these, but=
=20
rather, "run", which is a Capistrano command.

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

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

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

Homer Najafi

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
 
D

David Masover

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top