Skip to content

Instantly share code, notes, and snippets.

@chadselph
Created April 29, 2021 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadselph/a5af9ce660c7cdb73390db54301ec346 to your computer and use it in GitHub Desktop.
Save chadselph/a5af9ce660c7cdb73390db54301ec346 to your computer and use it in GitHub Desktop.
ugly ftp2http server
package com.goswiftly.http2ftp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URL;
import java.util.Base64;
import static spark.Spark.*;
public class Server {
private static final Logger logger = LoggerFactory.getLogger(Server.class);
public static void main(String[] args) {
get("/*", (req, res) ->
{
res.header("Content-Type", "application/zip");
String url = "ftp:/" + getAuthString(req.headers("Authentication")) + req.pathInfo();
logger.info("Fetching {}", url);
return new URL(url).openStream().readAllBytes();
}
);
}
static String getAuthString(String authHeader) {
if (authHeader == null) return "";
else return new String(Base64.getDecoder().decode(authHeader)) + "@";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment