Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
yangziwen committed Aug 29, 2018
1 parent cf36472 commit c9ad477
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM openjdk:8-jre-alpine
WORKDIR /usr/src/myapp
ENV PASSIVE_ADDRESS=127.0.0.1 PASSIVE_PORTS=40000-40060
WORKDIR /zy-ftp
ENV LOCAL_IP 0.0.0.0
ENV LOCAL_PORT 21
ENV PASSIVE_ADDRESS 127.0.0.1
ENV PASSIVE_PORTS 40000-40060
COPY target/zy-ftp.jar zy-ftp.jar
CMD ["sh", "-c", "java -jar zy-ftp.jar -c server.config -l zy-ftp.log --passive-address $PASSIVE_ADDRESS --passive-ports $PASSIVE_PORTS"]
EXPOSE 8021
CMD ["sh", "-c", "java -jar zy-ftp.jar -c server.config -l zy-ftp.log --passive-address $PASSIVE_ADDRESS --passive-ports $PASSIVE_PORTS --local-ip $LOCAL_IP --local-port $LOCAL_PORT"]
EXPOSE 21
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.io.File;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

Expand Down Expand Up @@ -47,7 +46,7 @@ public class FtpServerConfig {

private static final String DEFAULT_HOME_DIRECTORY = "res/";

private SocketAddress localAddress;
private InetSocketAddress localAddress;

private int maxLogins;

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/io/github/yangziwen/zyftp/main/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.yangziwen.zyftp.main;

import java.io.File;
import java.net.InetSocketAddress;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -31,6 +32,18 @@ public class Main {
required = false)
private File logFile = new File("log/zy-ftp.log");

@Parameter(
names = {"--local-ip"},
description = "specify the local ip",
required = false)
private String localIp;

@Parameter(
names = {"--local-port"},
description = "specify the local port",
required = false)
private Integer localPort;

@Parameter(
names = {"--passive-address"},
description = "specify the passive address",
Expand Down Expand Up @@ -80,6 +93,15 @@ public void run() throws Exception {

FtpServerContext context = new FtpServerContext(configFile);

InetSocketAddress address = context.getServerConfig().getLocalAddress();
if (StringUtils.isNotBlank(localIp) && !localIp.equals(address.getHostString())) {
address = new InetSocketAddress(localIp, address.getPort());
context.getServerConfig().setLocalAddress(address);
}
if (localPort != null && !localPort.equals(address.getPort())) {
address = new InetSocketAddress(address.getHostString(), localPort);
context.getServerConfig().setLocalAddress(address);
}
if (StringUtils.isNotBlank(passiveAddress)) {
context.getServerConfig().setPassiveAddress(passiveAddress);
}
Expand Down

0 comments on commit c9ad477

Please sign in to comment.