ssh & scp using ruby code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • littlemaster
    New Member
    • Apr 2010
    • 25

    ssh & scp using ruby code

    require 'rubygems'
    require 'net/ssh'
    require 'net/sftp'
    Net::SSH.start( '192.168.1.32', 'test', 'test') do |ssh|
    ssh.sftp.connec t do |sftp|

    dir=sftp.opendi r("/home/delivery_team/Plan\ of\ work")
    for item in sftp.readdir(di r)
    if not (item.filename == "." or item.filename == "..")
    source = sftp.open("/home/user1/work/Plan\ of\ work/Deliveryteam_da ily_updation.od s")
    target = File.open("/home/test/Deliveryteam_da ily_updation.od s", "w")
    target.write(sf tp.read(source) )
    sftp.close_hand le(source)
    target.close
    end
    end
    sftp.close_hand le(dir)
    end
    end


    (Note: In this we need to give the username and password of ssh machine.)
Working...