我有一个脚本,可以从一个服务器到另一个服务器进行文件传输,但它会出错:
Net::SCP::Error (SCP did not finish successfully ()):
Run Code Online (Sandbox Code Playgroud)
有谁能够帮我?这是我的代码.
Net::SCP.start( 's.com', 'username', :password => 'password' ) do|scp|
scp.upload!( source, destination )
end
Run Code Online (Sandbox Code Playgroud)
我有一个稍微不同的错误,其中包括parens中的退出代码:
Net::SCP::Error Exception: SCP did not finish successfully (1)
Run Code Online (Sandbox Code Playgroud)
我一开始认为这可能是因为源文件不存在或目标目录不存在,正如其他人所提到的那样,但事实证明是因为我传递的是源文件的路径名对象而不是字符串.
my_file = Rails.root.join('config/my_file') # my_file.class => Pathname
scp.upload!(my_file, "/var/tmp/dev.pub")
<Net::SCP::Error: SCP did not finish successfully (1)>
"gems/net-scp-1.0.4/lib/net/scp.rb:352:in `start_command'", "gems/net-ssh-2.6.7/lib/net/ssh/connection/channel.rb:590:in `call'",
"gems/net-ssh-2.6.7/lib/net/ssh/connection/channel.rb:590:in `do_close'", "gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:580:in `channel_close'", "gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:459:in `send'",
"gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:459:in `dispatch_incoming_packets'",
"gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:216:in `preprocess'", "gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:200:in `process'",
"gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:164:in `loop'", "gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:164:in `loop_forever'",
"gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:164:in `loop'", "gems/net-ssh-2.6.7/lib/net/ssh/connection/channel.rb:269:in `wait'",
"gems/net-scp-1.0.4/lib/net/scp.rb:279:in `upload!'",
Run Code Online (Sandbox Code Playgroud)
该文件被复制到正确的远程位置,但net-ssh中的某些内容退出1而不是0,我没有费心去查找该调用在堆栈跟踪中的位置
# gems/net-scp-1.0.4/lib/net/scp:352
channel.on_close { |ch| raise Net::SCP::Error, "SCP did not finish successfully (#{ch[:exit]})" if ch[:exit] != 0 }
Run Code Online (Sandbox Code Playgroud)
只需更改路径名对象一个字符串就可以了
my_file = Rails.root.join('config/my_file').to_s
scp.upload!(my_file, "/var/tmp/dev.pub")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9282 次 |
最近记录: |