0

我正在尝试使用 Docker 映像中的vsftpd 服务器重新创建Alpakka FTP-Source 连接器的遍历示例,但似乎无法连接。任何如何调整代码的指针都将非常受欢迎:

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。

4

1 回答 1

1

Source.to返回 a RunnableGraph,这是您仍然必须“运行”的“蓝图”:

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”速记:

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

于 2019-07-03T08:50:30.827 回答