Skip to content

Commit

Permalink
ByteBufferSourceClass to expose byte buffer uploading capabilities
Browse files Browse the repository at this point in the history
ScpTransferable new method to utilise aforementioned class
Version increment
  • Loading branch information
Maksymilian Pawlak committed Sep 14, 2015
1 parent bfc2c61 commit 8705ced
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import scalariform.formatter.preferences._

name := "scala-ssh"

version := "0.7.1"
version := "0.7.2"

organization := "com.decodified"

Expand Down
17 changes: 17 additions & 0 deletions src/main/scala/com/decodified/scalassh/ByteBufferSourceFile.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.decodified.scalassh

import java.io.{ ByteArrayInputStream, InputStream }

import net.schmizz.sshj.xfer.InMemorySourceFile

/**
* Created by M4ks on 14/09/2015.
*/
class ByteBufferSourceFile(bytes: Array[Byte], name: String) extends InMemorySourceFile {

override def getLength: Long = bytes.length

override def getName: String = name

override def getInputStream: InputStream = new ByteArrayInputStream(bytes)
}
6 changes: 4 additions & 2 deletions src/main/scala/com/decodified/scalassh/ScpTransferable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package com.decodified.scalassh

import net.schmizz.sshj.sftp.SFTPClient
import net.schmizz.sshj.xfer.scp.SCPFileTransfer
import net.schmizz.sshj.xfer.TransferListener
import net.schmizz.sshj.xfer.LoggingTransferListener
import net.schmizz.sshj.xfer.{ LoggingTransferListener, TransferListener }

trait ScpTransferable {
self: SshClient
Expand All @@ -29,6 +28,9 @@ trait ScpTransferable {
def upload(localPath: String, remotePath: String)(implicit listener: TransferListener = new LoggingTransferListener()): Validated[Unit] =
fileTransfer(_.upload(localPath, remotePath))(listener)

def uploadBytes(bytes: Array[Byte], name: String, remotePath: String)(implicit listener: TransferListener = new LoggingTransferListener()): Validated[Unit] =
fileTransfer(_.upload(new ByteBufferSourceFile(bytes, name), remotePath))(listener)

def download(remotePath: String, localPath: String)(implicit listener: TransferListener = new LoggingTransferListener()): Validated[Unit] =
fileTransfer(_.download(remotePath, localPath))(listener)
}

0 comments on commit 8705ced

Please sign in to comment.