How to auto-generate log-in URLs

Introduction

Monsta FTP allows you to log in via an encoded URL that contains the host details, username and password. This article explains how to dynamically create URLs so users can log in to Monsta FTP without entering any login details.

Prerequisites

Steps

The log-in URL is formatted as:

http(s)://{url}/#/c/{ftp host}/{ftp username}/{other parameters}

{} indicates variables, and the other parameters are JSON-formatted then base 64 encoded options like initial directory and password. To shorten the URL the parameter names are shortened too, using this lookup table:

"type": "t" FTP or SFTP
"configuration": "c"" Object

This configuration object is nested in the outer settings, and contains the actual login values as described below:

"passive": "v" FTP only
"ssl": "s" FTP only
"password": "p" FTP or SFTP with password authentication
"initialDirectory": "i" FTP or SFTP
"port": "o" FTP or SFTP
"authenticationModeName": "m" SFTP only, can be "Password", "PublicKeyFile", "HostKeyFile" or "Agent"
"privateKeyFilePath": "r" SFTP only, used only with authentication mode "PublicKeyFile" or "HostKeyFile"
"publicKeyFilePath": "q" SFTP only, used only with authentication mode "PublicKeyFile" or "HostKeyFile"

For example, to log in user testuser to my FTP on ftp.example.com, with password testpassword, and have the FTP in passive mode (the rest of the options are default, i.e. SSL off, initial directory is / and port is 21.)

First, create the JSON array with the options you want to set. For example:

Then replace the keys with the shortened values as described above:

{"t":"ftp","c":{"v":1,"p":"testpassword"}}

Then base64 encode it:

eyJ0IjoiZnRwIiwiYyI6eyJ2IjoxLCJwIjoidGVzdHBhc3N3b3JkIn19

Finally insert this and the username and host into the URL:

https://example.com/mftp/#/c/ftp.example.com/testuser/eyJ0IjoiiwiYyI...zdH3b3JkIn19

NOTE: Encoding is not the same as encryption, so the URL can be decoded.

Alternatively, you could just send the username and host, and the user would be prompted for the password, like this:

https://example.com/mftp/#/c/ftp.example.com/testuser/

Monsta FTP will try to authenticate with the given parameters. If it can not, then the user will be prompted with the standard login form to enter any values that were not provided.

Troubleshooting

If your log-in screen is loading with the posted values populating the fields this means the credentials in the URL have been rejected. Because URLs are encoded, certain characters will not pass through, for example a % symbol in the username will be converted to %25 and therefore prevent the login from working.