我正在尝试在Docker映像中使用traversal example为Alpakka FTP-Source连接器重新创建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。
答案 0 :(得分:1)
Source.to
返回一个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);