假设您将文件夹f_1
从本地计算机复制到目标计算机m_1
,并将/tmp
目录复制为mf_1
。
console:
[root@m_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:
[root@m_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:
[root@m_1 tmp] ls -a | grep mf_1 # => folder exists
[root@m_1 tmp] cd mf_1
[root@m_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)
连续两次,当文件夹存在且不是<?p>时,其行为方式相同
答案 0 :(得分:1)
如果来源是dir,我最后添加了一个点 这不是理想的,这是一个例子:
options = {recursive: true}
# target /tmp/mf_1 doesn't exist
Net::SCP.upload!(host, user, '~/f_1/.', '/tmp/mf_1', options)
# target /tmp/mf_1 has been created
# second time
Net::SCP.upload!(host, user, '~/f_1/.', '/tmp/mf_1', options)
# target /tmp/mf_1 has been overwritten
# not dir, but files in it, which is what we usually want