How to start Apache MINA FTP server using Scala / Java?

I am trying to embed an Apache MINA FTP server in my Scala application and I am having problems resolving it. I am using Apache FtpServer 1.05 and found a couple of examples on my site that don't seem to work when I Scala -ize them.

Here is my code:

package aperture import org.apache.ftpserver.listener.ListenerFactory import org.apache.ftpserver.ftplet._ import org.apache.ftpserver.{FtpServerFactory, FtpServer} import java.io.File import org.apache.ftpserver.usermanager.{UserFactory, SaltedPasswordEncryptor, PropertiesUserManagerFactory} object Main { def main(args: Array[String]) { val serverFactory: FtpServerFactory = new FtpServerFactory() val listenerFactory: ListenerFactory = new ListenerFactory() listenerFactory.setPort(2221); listenerFactory.setServerAddress("localhost") listenerFactory.setImplicitSsl(false); serverFactory.addListener("default", listenerFactory.createListener()) val userManagerFactory: PropertiesUserManagerFactory = new PropertiesUserManagerFactory() userManagerFactory.setFile(new File("myusers.properties")) userManagerFactory.setPasswordEncryptor(new SaltedPasswordEncryptor()) val userManager: UserManager = userManagerFactory.createUserManager() val userFact: UserFactory = new UserFactory() userFact.setName("myNewUser") userFact.setPassword("secret") userFact.setHomeDirectory("ftproot") val user: User = userFact.createUser() userManager.save(user) serverFactory.setUserManager(userManagerFactory.createUserManager()) // start the server val server: FtpServer = serverFactory.createServer() server.start() } } 

The code is valid and the server starts working on port 2221, but I can’t connect to it: ftp: localhost:2221: No address associated with hostname and ftp: 127.0.0.1:2221: Name or service not known .

Any thoughts?

+4
source share
1 answer

I did two things wrong:

  • I connected to the ftp server using the ftp localhost:2221 command instead of the correct path (with a space instead of a colon) ftp localhost 2221 .
  • I created a UserManager but never used it. I changed serverFactory.setUserManager(userManagerFactory.createUserManager()) to serverFactory.setUserManager(userManager) .
+3
source

All Articles