How to enter a remote directory on Ruby NET:SFTP?

半城伤御伤魂 提交于 2019-12-24 07:47:36

问题


How to enter a directory like the command - cd, thus operate remote files without a path prefix ?

Here is my current code.

Net::SFTP.start do |sftp|
  sftp.rename!(REMOTE_PATH + "latest.zip", REMOTE_PATH + "latest.back.zip")
  sftp.upload!("latest.zip", REMOTE_PATH + "latest.zip")
end

I would like to have:

sftp.cd REMOTE_PATH    
sftp.rename!("latest.zip", "latest.back.zip")
sftp.upload!("latest.zip", "latest.zip")

回答1:


I found a solution, which is use the SSH connect instead.. Not works. SFTP path seems irrelevant to SSH path. Let me know if you have other options.

 Net::SSH.start("localhost", "user", "password") do |ssh|
    ssh.sftp.upload!("/local/file.tgz", "/remote/file.tgz")
    ssh.exec! "cd /some/path && tar xf /remote/file.tgz && rm /remote/file.tgz"
  end


来源:https://stackoverflow.com/questions/1619129/how-to-enter-a-remote-directory-on-ruby-netsftp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!