ftpakkaalpakkavsftpd

Can't connect to vsftpd server with alpakka (akka-streams)


I'm trying to recreate the traversal example for the Alpakka FTP-Source connector with a vsftpd server in a Docker image, but can't seem to connect. Any pointers how to adjust the code would be very welcome:

FtpSettings ftpSettings = FtpSettings
  .create(InetAddress.getLocalhost())
  .withPort(21)
  .withCredentials(FtpCredentials.NonAnonFtpCredentials.create("news", "test"))
  .withBinary(true)
  .withPassiveMode(true)
  .withConfigureConnectionConsumer(
    (FTPClient ftpClient) -> {
      ftpClient.addProtocolCommandListener(
        new PrintCommandListener(new PrintWriter(System.out), true));
    });

Source<FtpFile, NotUsed> ftp = Ftp.ls("/", ftpSettings);
ftp.to(Sink.foreach(s -> LOGGER.info(s.name())));

FYI: The login information is working e.g. with filezilla.


Solution

  • Source.to returns a RunnableGraph, which is a 'blueprint' that you still have to 'run':

    import akka.actor.ActorSystem;
    import akka.stream.Materializer;
    import akka.stream.ActorMaterializer;
    
    // Create the blueprint:
    RunnableGraph blueprint = ftp.to(Sink.foreach(s -> LOGGER.info(s.name())));
    
    // Create the system to run the stream in:
    ActorSystem system = ActorSystem.create();
    Materializer materializer = ActorMaterializer.create(system);
    
    // Run the stream:
    blueprint.run(materializer);
    

    You can also use the 'runWith' shorthand:

    ftp.runWith(Sink.foreach(s -> LOGGER.info(s.name())), materializer);