Skip to content

Commit 10e6831

Browse files
author
Florent Clairambault
committed
Passive port allocation fix + docker integration improvements
1 parent 958f831 commit 10e6831

File tree

7 files changed

+21
-37
lines changed

7 files changed

+21
-37
lines changed

.github/workflows/docker-test.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
ftpserver:
1414
image: ftpserver/ftpserver
1515
ports:
16-
- 2121:2121
16+
- 2121-2200:2121-2200
1717

1818
steps:
1919
- name: Run sample
@@ -26,22 +26,21 @@ jobs:
2626
sudo apt-get install netcat curl -y
2727
2828
# Getting a file
29-
curl -o file.bin https://github.com/fclairamb/ftpserver/releases/download/v0.5/ftpserver-linux-amd64
29+
curl https://placekitten.com/2048/2048 -o kitty.jpg
3030
3131
# Waiting for server to be ready
3232
while ! nc -z localhost ${SERVER_PORT} </dev/null; do sleep 1; done
3333
3434
# Upload a file
35-
curl -P - -T file.bin ftp://test:test@localhost:2121/remote.bin
35+
curl -P - -T kitty.jpg ftp://test:test@localhost:${SERVER_PORT}/remote.jpg
3636
3737
# Download a file
38-
curl -P - ftp://test:test@localhost:2121/remote.bin -o remote.bin
38+
curl -P - ftp://test:test@localhost:2121/remote.jpg -o remote.jpg
3939
4040
# Checking that the output file exists
41-
if [ ! -f remote.bin ]; then
41+
if [ ! -f remote.jpg ]; then
4242
exit 1
4343
fi
4444
4545
# Comparing file contents
46-
diff file.bin remote.bin
47-
46+
diff kitty.jpg remote.jpg

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ FROM alpine:3.11.6
44
EXPOSE 2121-2200
55
RUN mkdir -p /data
66
COPY ftpserver /bin/ftpserver
7-
COPY settings_test.toml /etc/ftpserver_test.toml
87
ENTRYPOINT [ "/bin/ftpserver", "-data=/data" ]

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,11 @@ mkdir -p data
6868
docker run --rm -d -p 2121-2200:2121-2200 -v $(pwd)/data:/data fclairamb/ftpserver
6969

7070
# Download some file
71-
if [ ! -f file.bin ]; then
72-
wget -O file.bin.tmp https://github.com/fclairamb/ftpserver/releases/download/v0.5/ftpserver-linux-amd64 && mv file.bin.tmp file.bin
71+
if [ ! -f kitty.jpg ]; then
72+
curl -o kitty.jpg.tmp https://placekitten.com/2048/2048 && mv kitty.jpg.tmp kitty.jpg
7373
fi
7474

75-
# Connecting to it and uploading a file
76-
ftp ftp://test:test@localhost:2121
77-
put file.bin
78-
quit
79-
ls -lh data/file.bin
75+
curl -v -T kitty.bin ftp://test:test@localhost:2121/
8076
```
8177

8278
## The driver

local-docker-test.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ docker rm -f ftpserver ||:
44

55
GOOS=linux GOARCH=amd64 go build
66
docker build . -t test
7-
docker run --name ftpserver -p 2121:2121 -p 2122:2122 -p 2123:2123 test -conf /etc/ftpserver_test.toml &
8-
sleep 1
9-
curl -v -T main.go ftp://test:test@localhost:2121/
7+
if [ ! -f kitty.jpg ]; then
8+
curl -o kitty.jpg.tmp https://placekitten.com/2048/2048 && mv kitty.jpg.tmp kitty.jpg
9+
fi
10+
docker run --name ftpserver -p 2121-2200:2121-2200 test &
11+
while ! nc -z localhost 2121 </dev/null; do sleep 1; done
12+
curl -v -T kitty.jpg ftp://test:test@localhost:2121/

main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ func signalHandler() {
102102

103103
func confFileContent() []byte {
104104
str := `# ftpserver configuration file
105-
#
106-
# These are all the config parameters with their default values. If not present,
107105
108106
# Max number of control connections to accept
109107
# max_connections = 0
@@ -114,7 +112,7 @@ max_connections = 10
114112
# listen_addr="0.0.0.0:2121"
115113
116114
# Public host to expose in the passive connection
117-
# public_host = ""
115+
public_host = "127.0.0.1"
118116
119117
# Idle timeout time
120118
# idle_timeout = 900

sample/sample_driver.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,11 @@ func (driver *ClientDriver) OpenFile(cc server.ClientContext, path string, flag
313313
if (flag & os.O_WRONLY) != 0 {
314314
flag |= os.O_CREATE
315315
if (flag & os.O_APPEND) == 0 {
316-
if err := os.Remove(path); err != nil {
317-
fmt.Println("Problem removing file", path, "err:", err)
316+
_, err := os.Stat(path)
317+
if !os.IsNotExist(err) {
318+
if err := os.Remove(path); err != nil {
319+
fmt.Println("Problem removing file", path, "err:", err)
320+
}
318321
}
319322
}
320323
}

settings_test.toml

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)