SFTP writing is too slow in akka streams

i am trying to write to an sftp location with SFTP as sink , and for an 1MB file to write from my application it is taking almost 10 minutes.

how can i improve this.

i tried using “maxUnconfirmedreads” to 64 . but, it didn’t improved my performance and i believe it is for reading from sftp

Below is my code snippet

class SftpUtility {

  implicit val system: ActorSystem = ActorSystem("SftpUtility")
  val streamName: String = system.settings.config.getString("stream.config.name")
  val sftpKeyPath: String = system.settings.config.getString(s"$streamName.sftpKeyFile")
  val userName: String = system.settings.config.getString(s"$streamName.userName")
  val hostName: String = system.settings.config.getString(s"$streamName.hostName")
  val credentials: FtpCredentials = FtpCredentials.create(userName, "")
  val identity: KeyFileSftpIdentity = SftpIdentity.createFileSftpIdentity(sftpKeyPath)
  val settings: SftpSettings = SftpSettings(InetAddress.getByName(hostName))
  def getWritable[T](properties: Map[String, String]): Graph[SinkShape[T], NotUsed] = {
    val fileName = getFileName(properties)
    GraphDSL.create() { implicit builder =>
      val sftpSink: SinkShape[T] = builder.add(Flow[T].map(row => ByteString(row.toString)).to(Sftp.toPath(fileName, settings)))

  def getFileName(properties:Map[String,String]): String ={
    val fileName = properties("targetFileName")
    val fileFormat = properties("fileFormat")
    val filePath = properties("targetFilePath")


I hope you already found the answer. Just stumbled upon this request and I had the same problem when writing files with SFTP. With me the problem was the fact that /dev/random on my linux machine was not returning random numbers fast enough to set up the SFTP connection. It had something to do that this random generator was slow due to the fact there was no desktop with I think mouse movement. I think i did a ln of this /dev/random to work a little bit different and then SFTP was fast. So check your random generator that is being used by the java SFT client lib used.