仅当目录不存在时,如何才能通过 SFTP 在 Ruby 上创建目录?
我现在有以下代码:
Net::SFTP.start( ip, id, :password => pass, :port=> port ) do |sftp|
sftp.mkdir! remotePath
sftp.upload!(localPath + localfile, remotePath + remotefile)
end
Run Code Online (Sandbox Code Playgroud)
我第一次创建目录没有问题,但它会尝试重新创建相同的目录,即使它已经存在并且它会抛出一个错误。
有谁知道如何做到这一点?
在使用 fileutils 时,有这样的代码:
FileUtils.mkdir_p(remotePath) unless File.exists?(remotePath)
Run Code Online (Sandbox Code Playgroud)
有什么办法可以通过 SFTP 做同样的事情吗?