2
假設您將文件夾f_1
從本地機器複製到目標機器m_1
並將其作爲mf_1
複製到/tmp
目錄中。net :: scp複製/覆蓋文件夾
console:
[[email protected]_1 tmp] ls -a | grep mf_1 # => doesn't exist
irb:
options = {recursive: true}
Net::SCP.upload!(host, user, '~/f_1', '/tmp/mf_1', options)
console:
[[email protected]_1 tmp] ls -a | grep mf_1 # => folder exists, everything is fine
# but then, if you try to overwrite the existing folder...
irb:
Net::SCP.upload!(host, user, '~/f_1', '/tmp/mf_1', options)
console:
[[email protected]_1 tmp] ls -a | grep mf_1 # => folder exists
[[email protected]_1 tmp] cd mf_1
[[email protected]_1 m_f1] ls # => f_1 => /tmp/mf_1/f_1
所以,與其mf_1
不被覆蓋夾複製的/tmp/mf_1
內,造成/tmp/mf_1/f_1
。
的問題是非常簡單的,如何保留行爲,因此它是一致的,並呼籲
Net::SCP.upload!(host, user, '~/f_1', '/tmp/mf_1', options)
連續兩次將採取同樣的方式既當文件夾是否存在不?
您應該考慮使用SFTP而不是SCP如果你能。 – Kenster
@Kenster,你能舉個例子嗎? – ted