scala-sshでscp
PublicKeyLoginはデフォルトで ~/.ssh/id_rsa
と ~/.ssh/id_dsa
を秘密鍵として使う。のだけど、環境によるのだろうか、"~" がユーザのホームディレクトリとして展開されないので、鍵は自分でちゃんとフルパスを指定。
val host = "xxx.example.com" val home = System.getProperty("user.home") SSH(host, HostConfig( PublicKeyLogin("xfan", s"$home/.ssh/id_rsa"), hostKeyVerifier = HostKeyVerifiers.DontVerif, )) { client => client.upload(s"$home/images/neko.jpg", "/tmp") match { case Success(_) => // nothing to do case Failure(e) => throw e } }
かんたん。