[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Open a remote file and edit it

Paul Donaghy

7/5/2008 10:45:00 AM

Guys i want to open a file on another machine lets say test.txt, read it
find (grep) for example the text "localhost" and replace it with a
machine name and then close the file. I can connect to the machine using
ssh or sftp but as far editing a file I'm not sure how to.

Any help much appreciated.
--
Posted via http://www.ruby-....

1 Answer

Phlip

7/5/2008 10:59:00 AM

0

Paul Donaghy wrote:

> Guys i want to open a file on another machine lets say test.txt, read it
> find (grep) for example the text "localhost" and replace it with a
> machine name and then close the file. I can connect to the machine using
> ssh or sftp but as far editing a file I'm not sure how to.
>
> Any help much appreciated.

require 'net/ssh'
require 'net/sftp'

Net::SSH.start( 'server', 'user', 'password' ) do |session|
session.sftp.connect do |sftp|
# use sftp to pull the file to a local copy
# perform string surgery on the local copy
# and use sftp.put_file to copy it back
end
end