Created
December 27, 2014 00:25
-
-
Save mocyuto/d1f98d9845aedacb7258 to your computer and use it in GitHub Desktop.
ssh-scalaで画像をscpするコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File | |
import com.decodified.scalassh._ | |
import com.typesafe.config.ConfigFactory | |
import org.slf4j.LoggerFactory | |
import spray.http.StatusCodes | |
import scala.io.Source | |
/** | |
* Created by Yuto Suzuki on 2014/12/24. | |
*/ | |
object SshDao { | |
val config = ConfigFactory.load | |
def transportImg(filePath: String, fileName: String) = { | |
// 転送するホスト名 | |
val host = config.getString("img.server.host") | |
val logger = LoggerFactory.getLogger(getClass) | |
// user, password情報 | |
val hostConfig = HostConfig(PasswordLogin(config.getString("img.server.user"), config.getString("img.server.password"))) | |
// SSHをつなぐ | |
SSH(host, hostConfig) { client => | |
client.exec(s"mkdir ${filePath}").right.map { result => | |
logger.error(result.stdErrAsString()) | |
} | |
// 画像のSCP送信 | |
try client.upload(filePath + fileName, filePath + fileName).right.flatMap { _ => | |
client.exec("ls " + filePath + fileName).right.map { result => | |
logger.info(s"result: ${result.stdOutAsString()}") | |
} | |
} finally client.close() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment