Skip to content

Fixes asyncftpclient multiline reading, fixes #4684 #13242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2020
Merged
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
11 changes: 6 additions & 5 deletions lib/pure/asyncftpclient.nim
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@ type
const multiLineLimit = 10000

proc expectReply(ftp: AsyncFtpClient): Future[TaintedString] {.async.} =
result = await ftp.csock.recvLine()
var line = await ftp.csock.recvLine()
result = TaintedString(line)
var count = 0
while result[3] == '-':
while line[3] == '-':
## Multi-line reply.
let line = await ftp.csock.recvLine()
result.add("\n" & line)
line = await ftp.csock.recvLine()
string(result).add("\n" & line)
count.inc()
if count >= multiLineLimit:
raise newException(ReplyError, "Reached maximum multi-line reply count.")
Expand Down Expand Up @@ -178,7 +179,7 @@ proc connect*(ftp: AsyncFtpClient) {.async.} =
await ftp.csock.connect(ftp.address, ftp.port)

var reply = await ftp.expectReply()
if reply.startsWith("120"):
if string(reply).startsWith("120"):
# 120 Service ready in nnn minutes.
# We wait until we receive 220.
reply = await ftp.expectReply()
Expand Down