gpt4 book ai didi

ruby - 使用 Ruby 和 SCP/SSH,如何在上传副本之前确定文件是否存在

转载 作者:数据小太阳 更新时间:2023-10-29 08:17:58 26 4
gpt4 key购买 nike

我正在使用 SCP 将文件上传到远程服务器,但在执行此操作之前查看该文件是否存在的正确方法是什么?

最佳答案

你不能用 scp 做到这一点。但是你可以用 sftp. 来做它看起来像这样:

require 'net/sftp'

remote_path = "/path/to/remote/file"
Net::SFTP.start('host', 'username', :password => 'password') do |sftp|
sftp.stat!(remote_path) do |response|
unless response.ok?
sftp.upload!("/path/to/local/file", remote_path)
end
end

关于ruby - 使用 Ruby 和 SCP/SSH,如何在上传副本之前确定文件是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1625693/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com