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.
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.rmdirandFtp.rename, with the same accessors onSFtpandStubFtp. - 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.
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"
)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.
The rest of the documentation is organized as follows:
- Getting Started installs the library and runs a first program against a local FTP server.
- FTP, FTPS and SFTP explains the three protocols and how their behavior differs in ZIO FTP.
- Environment explains how the connection lives in the ZIO environment.
- The reference section documents every operation (Ftp API), every layer and constructor (docs/Connecting), and every settings type (FTP and FTPS settings, SFTP settings), plus FtpResource, Errors and TestFtp.
- The tutorial builds a small backup tool from scratch.
- The how-to guides solve one task each: uploading a file, downloading a file, listing a directory recursively, connecting over SFTP with a key, using FTPS, keeping a connection alive, testing without a server and calling an unwrapped client method.
Learn more on the ZIO FTP homepage!
For the general guidelines, see ZIO contributor's guide.
See the Code of Conduct