Net :: SCP ::错误(SCP没有成功完成()):

Shr*_*war 12 ruby-on-rails

我有一个脚本,可以从一个服务器到另一个服务器进行文件传输,但它会出错:

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)

rud*_*-n8 11

我今天遇到了这个问题.结果是我的本地文件(在你的例子中,源代码)指向一个不存在的文件.祝好运.


Eva*_*van 9

如果要将文件上载到远程服务器上尚不存在的文件夹,也会发生此错误.文件夹创建并非隐含在SCP中


mmr*_*ins 7

我有一个稍微不同的错误,其中包括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)


Leo*_*Shi 5

我有这个问题,只是解决了。本地路径和远程路径都应为完整路径(例如“ / home / root / folder”),而不应为“〜/ folder”的原因。


tro*_*skn 5

仅出于完整性考虑,如果您没有适当的权限写入目标,这也可能发生。