Skip to content

Commit 61d2ea7

Browse files
authored
net.ftp: fix get() command conversation, add test (fix #18858) (#26194)
1 parent d3b8c9b commit 61d2ea7

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎vlib/net/ftp/ftp.v‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ pub fn (mut zftp FTP) get(file string) ![]u8 {
249249
return error('Data connection not ready')
250250
}
251251
blob := dtp.read()!
252+
result, _ := zftp.read()!
253+
if result != complete {
254+
return error('`RETR` not ok')
255+
}
252256
dtp.close()
253257
return blob
254258
}

‎vlib/net/ftp/ftp_test.v‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,26 @@ fn ftp_client_test_inside() ! {
4949
}
5050
assert blob.len > 0
5151
}
52+
53+
fn test_ftp_get() ! {
54+
$if !network ? {
55+
return
56+
}
57+
58+
mut zftp := ftp.new()
59+
defer {
60+
zftp.close() or { panic(err) }
61+
}
62+
connect_result := zftp.connect('ftp.sunet.se:21')!
63+
assert connect_result
64+
login_result := zftp.login('ftp', 'ftp')!
65+
assert login_result
66+
pwd := zftp.pwd()!
67+
assert pwd.len > 0
68+
mut txt := zftp.get('robots.txt')!
69+
assert txt[0] == 35 // first byte is # char
70+
zftp.pwd()!
71+
zftp.cd('pub')!
72+
zftp.cd('..')!
73+
zftp.get('robots.txt')!
74+
}

0 commit comments

Comments
 (0)