Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Config

alias ExFTP.Auth.PassthroughAuth
alias ExFTP.Storage.S3Connector
alias ExFTP.Storage.FileConnector

config :ex_aws,
s3: [
Expand All @@ -11,3 +11,18 @@ config :ex_aws,
access_key_id: "",
secret_access_key: ""
]

config :ex_ftp,
ftp_port: "FTP_PORT" |> System.get_env("4040") |> String.to_integer(),
ftp_addr: System.get_env("FTP_ADDR", "127.0.0.1"),
min_passive_port: "MIN_PASSIVE_PORT" |> System.get_env("40002") |> String.to_integer(),
max_passive_port: "MAX_PASSIVE_PORT" |> System.get_env("40007") |> String.to_integer(),
authenticator: PassthroughAuth,
authenticator_config: %{
authenticated_url: nil,
authenticated_method: :get,
authenticated_ttl_ms: to_timeout(day: 1),
login_url: nil,
login_method: :get
},
storage_connector: FileConnector
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ config :ex_ftp,
authenticator_config: %{
authenticated_url: nil,
authenticated_method: :get,
authenticated_ttl_ms: 24 * 60 * 60 * 60 * 1000,
authenticated_ttl_ms: to_timeout(day: 1),
login_url: nil,
login_method: :get
},
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
localstack:
container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}"
image: localstack/localstack
ports:
- "4566:4566" # LocalStack Gateway
- "4510-4559:4510-4559" # external services port range
environment:
# LocalStack configuration: https://docs.localstack.cloud/references/configuration/
- DEBUG=${DEBUG:-0}
volumes:
- localstack-data:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"

volumes:
localstack-data: {}
7 changes: 4 additions & 3 deletions lib/ex_ftp/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ defmodule ExFTP.Application do

use Application

require Logger

@impl true
def start(_type, _args) do
port = Application.get_env(:ex_ftp, :ftp_port, 4041)

children = [
{Cachex, [:auth_cache]},
{DynamicSupervisor, name: ExFTP.WorkerSupervisor, strategy: :one_for_one},
{ExFTP.Server, port: port}
{ThousandIsland, port: port, handler_module: ExFTP.Worker, transport_options: [packet: :line]}
]

opts = [strategy: :one_for_one, name: ExFTP.Supervisor]

Logger.info("Accepting connections on port #{port}")
Supervisor.start_link(children, opts)
end
end
2 changes: 1 addition & 1 deletion lib/ex_ftp/ftp_common.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ defmodule ExFTP.Common do
def send_resp(code, msg, socket) when is_integer(code) and is_bitstring(msg) do
response = "#{code} #{msg}\r\n"
Logger.info("Sending FTP response:\t#{inspect(response)}")
:ok = :gen_tcp.send(socket, response)
:ok = ThousandIsland.Socket.send(socket, response)
end
end
8 changes: 5 additions & 3 deletions lib/ex_ftp/passive_socket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ defmodule ExFTP.PassiveSocket do
GenServer.call(pid, {:write, data, opts}, :infinity)
end

def close(nil), do: :ok

def close(pid) do
if Process.alive?(pid) do
GenServer.call(pid, {:close}, :infinity)
end
if Process.alive?(pid),
do: GenServer.call(pid, {:close}, :infinity),
else: :ok
end

# Server API
Expand Down
60 changes: 0 additions & 60 deletions lib/ex_ftp/server.ex

This file was deleted.

Loading
Loading