无法使用 alpakka (akka-streams) 连接到 vsftpd 服务器

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

我正在尝试在 Docker 图像中重新创建 traversal example for the Alpakka FTP-Source connector with a vsftpd server,但似乎无法连接。非常欢迎任何关于如何调整代码的指示:

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())));

仅供参考:登录信息有效,例如与 filezilla.

Source.to returns 一个 RunnableGraph,这是一个 'blueprint',你仍然需要 '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);

您也可以使用 'runWith' shorthand:

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