Skip to content
zioPublic

Repository files navigation

ZIO FTP

ZIO FTP is a ZIO client for file servers that speak FTP, FTPS or SFTP. Each file operation is a ZIO effect, every directory listing and download is a ZStream, and the connection is a layer that opens when the program starts and closes when it ends.

Production Ready CI Badge Sonatype Releases Sonatype Snapshots javadoc ZIO FTP

Features

ZIO FTP wraps two Java clients: Apache Commons Net for FTP and FTPS, and sshj for SFTP. It runs their blocking calls on ZIO's blocking thread pool and turns their errors into typed IOException failures. The library offers:

  • One set of operations for all three protocols: Ftp.ls, Ftp.lsDescendant, Ftp.stat, Ftp.readFile, Ftp.upload, Ftp.mkdir, Ftp.rm, Ftp.rmdir and Ftp.rename, with the same accessors on SFtp and StubFtp.
  • Streaming reads and writes, so large files never have to fit in memory.
  • Password and SSH key authentication for SFTP, and explicit or implicit TLS for FTPS.
  • Connection settings for passive mode, timeouts, TCP keepalive and proxies.
  • A test double that works on a local directory, so tests run without a server.

Installation

ZIO FTP is published for Scala 2.12, 2.13 and 3 on the JVM. To use it, add the following to your build.sbt:

libraryDependencies ++= Seq(
  // FTP, FTPS and SFTP clients as ZIO effects and streams (JVM only)
  "dev.zio" %% "zio-ftp" % "0.5.4"
)

Example

The following program connects to an FTP server, uploads a small file and prints the names in the root directory:

import zio._
import zio.ftp._
import zio.stream._

object QuickStart extends ZIOAppDefault {

  private val settings =
    UnsecureFtpSettings("127.0.0.1", 21, PasswordCredentials("one", "1234"))

  private val program =
    for {
      _     <- Ftp.upload("/hello.txt", ZStream.fromChunk(Chunk.fromArray("Hello, ZIO FTP!".getBytes)))
      names <- Ftp.ls("/").map(_.path).runCollect
      _     <- ZIO.foreachDiscard(names)(Console.printLine(_))
    } yield ()

  override def run = program.provide(unsecure(settings))
}

For SFTP, the same program uses SecureFtpSettings, the SFtp accessors and the secure layer. The Getting Started page runs a program like this one against a local server, step by step.

Learn More

The rest of the documentation is organized as follows:

Documentation

Learn more on the ZIO FTP homepage!

Contributing

For the general guidelines, see ZIO contributor's guide.

Code of Conduct

See the Code of Conduct

Support

Come chat with us on Badge-Discord.

License

License

Releases

Packages

Used by

Contributors

Languages