0

I have built a FTP Server in android app using https://mina.apache.org/ftpserver-project/documentation.html. I need to render a html page from Assets as my home page. But it is always listing a directory.

 connectionConfigFactory.isAnonymousLoginEnabled = true
    connectionConfigFactory.maxLogins = 1
    connectionConfigFactory.maxThreads = 1
    ftpServerFactory.connectionConfig = connectionConfigFactory.createConnectionConfig()
    ftpServer = ftpServerFactory.createServer()
    listenerFactory.setPort(2121)
    ftpServerFactory.addListener("default", listenerFactory.createListener())
    ftpServerFactory.ftplets.put(FTPLetImpl::class.java.getName(), FTPLetImpl())

    val files =
        File(Environment.getExternalStorageDirectory().path + "/users.properties")
    if (!files.exists()) {
        try {
            files.createNewFile()
        } catch (e: IOException) {
            e.printStackTrace()
        }
    }
    userManagerFactory.setFile(files)
    userManagerFactory.setPasswordEncryptor(SaltedPasswordEncryptor())
    val um: UserManager = userManagerFactory.createUserManager()
    val user = BaseUser()
    user.name = "anonymous"
    user.enabled = true
    val home =
        Environment.getExternalStorageDirectory().path + "/Test"
    user.homeDirectory = home

    val auths: MutableList<Authority> =
        ArrayList()
    val auth: Authority = WritePermission()
    val auth1: Authority = ConcurrentLoginPermission(MAX_CONCURRENT_LOGINS,MAX_CONCURRENT_LOGINS_PER_IP)
    val auth2: Authority = TransferRatePermission(Integer.MAX_VALUE, Integer.MAX_VALUE)
    auths.add(auth)
    auths.add(auth1)
    auths.add(auth2)
    user.authorities = auths

    try {
        ftpServerFactory.userManager.save(user)
    } catch (e1: FtpException) {
        e1.printStackTrace()
    }

Even though I set the user home directory as Html page. It gets downloaded in the browser & not rendering it

Even though I set the user home directory as Html page. It gets downloaded in the browser & not rendering it

venkatesh
  • 319
  • 2
  • 10

1 Answers1

1

It's an FTP server. So when an FTP client asks for a directory listing, it gets textual (in case of LIST) or even structured (in case of MLSD) information about files in the directory.

And it's up to the FTP client, how it displays that information to the user. You have no control over that. It's irrelevant that in your particular case, the FTP client is primarily a web browser. In this context, it is not a web browser, it is an FTP client.


If you want to produce an HTML page, you need to implement an HTTP server, not an FTP server.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992