2010-12-16 23 views
12

我有一個腳本,它會做從一個服務器上的文件轉移到另一個,但它給出了一個錯誤:的Net :: SCP ::錯誤(SCP沒有成功完成()):

Net::SCP::Error (SCP did not finish successfully()): 

可以在任何身體幫助我?這是我的代碼。

Net::SCP.start('s.com', 'username', :password => 'password') do|scp| 
    scp.upload!(source, destination) 
end 
+0

我知道這是舊的和回答,但我得到這個錯誤,當我試圖下載與Net :: SCP。對我來說問題是遠程SSH主機沒有安裝'openssh-clients'。 – ZombieDev 2014-04-03 16:12:57

回答

10

我今天有這個問題。發現我的本地文件(在你的例子中,來源)指向一個不存在的文件。祝你好運。

9

如果要將文件上傳到遠程服務器上尚不存在的文件夾,也會發生此錯誤。創建文件夾不是隱含在SCP中

3

我有這個問題,只是修復它。 本地和遠程路徑的原因應該是完全路徑,如'/ home/root/folder',而不應該是'〜/文件夾'。

+0

這是我的問題,面對它與[capistrano寶石](https://github.com/sgruhier/capistrano-db-tasks/blob/master/lib/capistrano-db-tasks/database.rb)是這個一個錯誤? – 2014-05-24 07:06:32

0

我有一個rakefile.rb,它定義了一個使用net/scp和基本密碼認證將文件上傳到遠程服務器的任務,即使我檢查了一個「Net :: SSH :: AuthenticationFailed」異常主機,用戶,密碼和文件字符串。我啓用

LogLevel INFO 

LogLevel DEBUG 

然後看到下面的輸出在服務器的日誌(例如,/var/log/auth.log),發現客戶端試圖使用公共密鑰認證因爲某些原因!

Nov 13 22:38:26 linux sshd[12514]: debug1: Forked child 12532. 
Nov 13 22:38:26 linux sshd[12532]: Set /proc/self/oom_score_adj to 0 
Nov 13 22:38:26 linux sshd[12532]: debug1: rexec start in 5 out 5 newsock 5 pipe 7 sock 8 
Nov 13 22:38:26 linux sshd[12532]: debug1: inetd sockets after dupping: 3, 3 
Nov 13 22:38:26 linux sshd[12532]: Connection from 192.168.112.1 port 38391 
Nov 13 22:38:26 linux sshd[12532]: debug1: Client protocol version 2.0; client software version Ruby/Net::SSH_2.6.1 i386-mingw32 
Nov 13 22:38:26 linux sshd[12532]: debug1: no match: Ruby/Net::SSH_2.6.1 i386-mingw32 
Nov 13 22:38:26 linux sshd[12532]: debug1: Enabling compatibility mode for protocol 2.0 
Nov 13 22:38:26 linux sshd[12532]: debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1 
Nov 13 22:38:26 linux sshd[12532]: debug1: permanently_set_uid: 102/65534 [preauth] 
Nov 13 22:38:26 linux sshd[12532]: debug1: list_hostkey_types: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256 [preauth] 
Nov 13 22:38:26 linux sshd[12532]: debug1: SSH2_MSG_KEXINIT sent [preauth] 
Nov 13 22:38:26 linux sshd[12532]: debug1: SSH2_MSG_KEXINIT received [preauth] 
Nov 13 22:38:26 linux sshd[12532]: debug1: kex: client->server aes128-cbc hmac-sha1 none [preauth] 
Nov 13 22:38:26 linux sshd[12532]: debug1: kex: server->client aes128-cbc hmac-sha1 none [preauth] 
Nov 13 22:38:26 linux sshd[12532]: debug1: SSH2_MSG_KEX_DH_GEX_REQUEST received [preauth] 
Nov 13 22:38:26 linux sshd[12532]: debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent [preauth] 
Nov 13 22:38:26 linux sshd[12532]: debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT [preauth] 
Nov 13 22:38:27 linux sshd[12532]: debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent [preauth] 
Nov 13 22:38:27 linux sshd[12532]: debug1: SSH2_MSG_NEWKEYS sent [preauth] 
Nov 13 22:38:27 linux sshd[12532]: debug1: expecting SSH2_MSG_NEWKEYS [preauth] 
Nov 13 22:38:27 linux sshd[12532]: debug1: SSH2_MSG_NEWKEYS received [preauth] 
Nov 13 22:38:27 linux sshd[12532]: debug1: KEX done [preauth] 
Nov 13 22:38:27 linux sshd[12532]: debug1: userauth-request for user root service ssh-connection method publickey [preauth] 
Nov 13 22:38:27 linux sshd[12532]: debug1: attempt 0 failures 0 [preauth] 

    (pause in time) 

Nov 13 22:38:38 linux sshd[12532]: debug1: test whether pkalg/pkblob are acceptable [preauth] 
Nov 13 22:38:38 linux sshd[12532]: debug1: PAM: initializing for "root" 
Nov 13 22:38:38 linux sshd[12532]: debug1: PAM: setting PAM_RHOST to "np-complete.local" 
Nov 13 22:38:38 linux sshd[12532]: debug1: PAM: setting PAM_TTY to "ssh" 
Nov 13 22:38:38 linux sshd[12532]: debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048 
Nov 13 22:38:38 linux sshd[12532]: debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048 
Nov 13 22:38:38 linux sshd[12532]: debug1: temporarily_use_uid: 0/0 (e=0/0) 
Nov 13 22:38:38 linux sshd[12532]: debug1: trying public key file /root/.ssh/authorized_keys 
Nov 13 22:38:38 linux sshd[12532]: debug1: Could not open authorized keys '/root/.ssh/authorized_keys': No such file or directory 
Nov 13 22:38:38 linux sshd[12532]: debug1: restore_uid: 0/0 
Nov 13 22:38:38 linux sshd[12532]: debug1: temporarily_use_uid: 0/0 (e=0/0) 
Nov 13 22:38:38 linux sshd[12532]: debug1: trying public key file /root/.ssh/authorized_keys2 
Nov 13 22:38:38 linux sshd[12532]: debug1: Could not open authorized keys '/root/.ssh/authorized_keys2': No such file or directory 
Nov 13 22:38:38 linux sshd[12532]: debug1: restore_uid: 0/0 
Nov 13 22:38:38 linux sshd[12532]: Failed publickey for root from 192.168.112.1 port 38391 ssh2 
Nov 13 22:38:38 linux sshd[12532]: Connection closed by 192.168.112.1 [preauth] 
Nov 13 22:38:38 linux sshd[12532]: debug1: do_cleanup [preauth] 
Nov 13 22:38:38 linux sshd[12532]: debug1: monitor_read_log: child log fd closed 
Nov 13 22:38:38 linux sshd[12532]: debug1: do_cleanup 
Nov 13 22:38:38 linux sshd[12532]: debug1: PAM: cleanup 

所以看到發生了什麼事情我改變了我的代碼,包括:在SCP的選項SSH密鑰,指定我只支持密碼認證:

Net::SCP.upload!(:remote_server, :remote_user, local_file, remote_file, 
       { 
        :password => "(my password)", 
        :ssh => {:auth_methods => ["password"]} 
       } 
      ) 

,這導致在服務器上的以下信息:

Nov 13 23:00:36 linux sshd[12514]: debug1: Forked child 13376. 
Nov 13 23:00:36 linux sshd[13376]: Set /proc/self/oom_score_adj to 0 
Nov 13 23:00:36 linux sshd[13376]: debug1: rexec start in 5 out 5 newsock 5 pipe 7 sock 8 
Nov 13 23:00:36 linux sshd[13376]: debug1: inetd sockets after dupping: 3, 3 
Nov 13 23:00:36 linux sshd[13376]: Connection from 192.168.112.1 port 38631 
Nov 13 23:00:36 linux sshd[13376]: debug1: Client protocol version 2.0; client software version Ruby/Net::SSH_2.6.1 i386-mingw32 
Nov 13 23:00:36 linux sshd[13376]: debug1: no match: Ruby/Net::SSH_2.6.1 i386-mingw32 
Nov 13 23:00:36 linux sshd[13376]: debug1: Enabling compatibility mode for protocol 2.0 
Nov 13 23:00:36 linux sshd[13376]: debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1 
Nov 13 23:00:36 linux sshd[13376]: debug1: permanently_set_uid: 102/65534 [preauth] 
Nov 13 23:00:36 linux sshd[13376]: debug1: list_hostkey_types: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256 [preauth] 
Nov 13 23:00:36 linux sshd[13376]: debug1: SSH2_MSG_KEXINIT sent [preauth] 
Nov 13 23:00:36 linux sshd[13376]: debug1: SSH2_MSG_KEXINIT received [preauth] 
Nov 13 23:00:36 linux sshd[13376]: debug1: kex: client->server aes128-cbc hmac-sha1 none [preauth] 
Nov 13 23:00:36 linux sshd[13376]: debug1: kex: server->client aes128-cbc hmac-sha1 none [preauth] 
Nov 13 23:00:36 linux sshd[13376]: debug1: SSH2_MSG_KEX_DH_GEX_REQUEST received [preauth] 
Nov 13 23:00:36 linux sshd[13376]: debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent [preauth] 
Nov 13 23:00:36 linux sshd[13376]: debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT [preauth] 
Nov 13 23:00:37 linux sshd[13376]: debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent [preauth] 
Nov 13 23:00:37 linux sshd[13376]: debug1: SSH2_MSG_NEWKEYS sent [preauth] 
Nov 13 23:00:37 linux sshd[13376]: debug1: expecting SSH2_MSG_NEWKEYS [preauth] 
Nov 13 23:00:37 linux sshd[13376]: debug1: SSH2_MSG_NEWKEYS received [preauth] 
Nov 13 23:00:37 linux sshd[13376]: debug1: KEX done [preauth] 
Nov 13 23:00:37 linux sshd[13376]: Connection closed by 192.168.112.1 [preauth] 
Nov 13 23:00:37 linux sshd[13376]: debug1: do_cleanup [preauth] 
Nov 13 23:00:37 linux sshd[13376]: debug1: monitor_read_log: child log fd closed 
Nov 13 23:00:37 linux sshd[13376]: debug1: do_cleanup 

顯然他們未能就如何做認證同意....希望這是人們通過它來幫助。如果/當我發現爲什麼會發生這種情況時,我會更新它。

5

我有一個稍微不同的錯誤,包括在括號退出代碼:

Net::SCP::Error Exception: SCP did not finish successfully (1) 

我起初這會已經引起源文件不存在或爲其他人所說的不存在目標目錄想通,但事實證明是因爲我傳遞的是源文件的路徑名對象而不是字符串。

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!'", 

該文件已被複制到正確的位置偏遠,但一些在網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 } 

只是改變了路徑對象的字符串使一切工作

my_file = Rails.root.join('config/my_file').to_s 
scp.upload!(my_file, "/var/tmp/dev.pub") 
+1

輝煌。這樣的事情我也經歷過。這應該在Gem中真正解決。 – slhck 2014-08-12 10:04:41

4

只是爲了完整起見,這也可以,如果你沒有適當的權限寫入到目標發生。

+0

是的,這發生在我身上。談論一個超級無用的錯誤消息。 – racl101 2017-01-10 03:18:15