From 32ec7f2f5fb3e777fcb9730571c34633bfa5bcfb Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 26 Jun 2015 09:18:40 +0200 Subject: [PATCH 1/7] Allow AsyncFtpClient and ftpclient to check 220 messages As many ftp servers can answer with multiple 220 messages these two libraries have to handle multiline 220 messages before send user and pass messages. --- lib/pure/asyncftpclient.nim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/pure/asyncftpclient.nim b/lib/pure/asyncftpclient.nim index daf69d59f..c3545ada8 100644 --- a/lib/pure/asyncftpclient.nim +++ b/lib/pure/asyncftpclient.nim @@ -79,7 +79,13 @@ proc connect*(ftp: AsyncFtpClient) {.async.} = # 120 Service ready in nnn minutes. # We wait until we receive 220. reply = await ftp.expectReply() - assertReply(reply, "220") + + # Handle 220 messages from the server + if reply.startsWith("220"): + assertReply(reply, "220") + while reply.continuesWith("-", 3): # handle multiline 220 message + assertReply(reply, "220") + reply = await ftp.expectReply() if ftp.user != "": assertReply(await(ftp.send("USER " & ftp.user)), "230", "331") From c687e2b9d2fefa362990f6f608c59c92a2575a3d Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 26 Jun 2015 09:24:58 +0200 Subject: [PATCH 2/7] Allow ftp client to handle 220 multiline messages --- lib/pure/ftpclient.nim | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/pure/ftpclient.nim b/lib/pure/ftpclient.nim index dd141eb01..7ede6b479 100644 --- a/lib/pure/ftpclient.nim +++ b/lib/pure/ftpclient.nim @@ -263,8 +263,18 @@ proc connect*[T](ftp: FtpBase[T]) = else: {.fatal: "Incorrect socket instantiation".} - # TODO: Handle 120? or let user handle it. - assertReply ftp.expectReply(), "220" + var reply = ftp.expectReply() + if reply.startsWith("120"): + # 120 Service ready in nnn minutes. + # We wait until we receive 220. + reply = ftp.expectReply() + + # Handle 220 messages from the server + if reply.startsWith("220"): + assertReply(reply, "220") + while reply.continuesWith("-", 3): # handle multiline 220 message + assertReply(reply, "220") + reply = await ftp.expectReply() if ftp.user != "": assertReply(ftp.send("USER " & ftp.user), "230", "331") From 96e5c7c3b960fd617428cea3e64236dc8f430547 Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 26 Jun 2015 09:26:51 +0200 Subject: [PATCH 3/7] Fix remove async call --- lib/pure/ftpclient.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/ftpclient.nim b/lib/pure/ftpclient.nim index 7ede6b479..522f42cf8 100644 --- a/lib/pure/ftpclient.nim +++ b/lib/pure/ftpclient.nim @@ -274,7 +274,7 @@ proc connect*[T](ftp: FtpBase[T]) = assertReply(reply, "220") while reply.continuesWith("-", 3): # handle multiline 220 message assertReply(reply, "220") - reply = await ftp.expectReply() + reply = ftp.expectReply() if ftp.user != "": assertReply(ftp.send("USER " & ftp.user), "230", "331") From 04f64fde855c83671fa0a36271253f66121cb2e6 Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 26 Jun 2015 09:35:35 +0200 Subject: [PATCH 4/7] Fix no async code --- lib/pure/ftpclient.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pure/ftpclient.nim b/lib/pure/ftpclient.nim index 522f42cf8..eaa8c82b2 100644 --- a/lib/pure/ftpclient.nim +++ b/lib/pure/ftpclient.nim @@ -271,9 +271,9 @@ proc connect*[T](ftp: FtpBase[T]) = # Handle 220 messages from the server if reply.startsWith("220"): - assertReply(reply, "220") + assertReply ftp.expectReply(), "220" while reply.continuesWith("-", 3): # handle multiline 220 message - assertReply(reply, "220") + assertReply ftp.expectReply(), "220" reply = ftp.expectReply() if ftp.user != "": From 40a4a393740e3cf72dd37a243d5b72d7cde7f721 Mon Sep 17 00:00:00 2001 From: Luca Date: Sat, 27 Jun 2015 14:40:12 +0200 Subject: [PATCH 5/7] Remove redundant 220 check --- lib/pure/ftpclient.nim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/pure/ftpclient.nim b/lib/pure/ftpclient.nim index eaa8c82b2..301ca227a 100644 --- a/lib/pure/ftpclient.nim +++ b/lib/pure/ftpclient.nim @@ -270,11 +270,10 @@ proc connect*[T](ftp: FtpBase[T]) = reply = ftp.expectReply() # Handle 220 messages from the server - if reply.startsWith("220"): + assertReply ftp.expectReply(), "220" + while reply.continuesWith("-", 3): # handle multiline 220 message assertReply ftp.expectReply(), "220" - while reply.continuesWith("-", 3): # handle multiline 220 message - assertReply ftp.expectReply(), "220" - reply = ftp.expectReply() + reply = ftp.expectReply() if ftp.user != "": assertReply(ftp.send("USER " & ftp.user), "230", "331") From 88ae4c18593c61ed1c67d074cee373226c41ab32 Mon Sep 17 00:00:00 2001 From: Luca Date: Sat, 27 Jun 2015 14:40:44 +0200 Subject: [PATCH 6/7] Remove redundant 220 check --- lib/pure/asyncftpclient.nim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/pure/asyncftpclient.nim b/lib/pure/asyncftpclient.nim index c3545ada8..979b0d649 100644 --- a/lib/pure/asyncftpclient.nim +++ b/lib/pure/asyncftpclient.nim @@ -81,11 +81,10 @@ proc connect*(ftp: AsyncFtpClient) {.async.} = reply = await ftp.expectReply() # Handle 220 messages from the server - if reply.startsWith("220"): + assertReply(reply, "220") + while reply.continuesWith("-", 3): # handle multiline 220 message assertReply(reply, "220") - while reply.continuesWith("-", 3): # handle multiline 220 message - assertReply(reply, "220") - reply = await ftp.expectReply() + reply = await ftp.expectReply() if ftp.user != "": assertReply(await(ftp.send("USER " & ftp.user)), "230", "331") From 110d84a9167ad077bb8ca983c43c8febc5780cc6 Mon Sep 17 00:00:00 2001 From: Luca Date: Sat, 27 Jun 2015 17:06:11 +0200 Subject: [PATCH 7/7] remove unnecessary function --- lib/pure/asyncftpclient.nim | 2 +- lib/pure/ftpclient.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pure/asyncftpclient.nim b/lib/pure/asyncftpclient.nim index 979b0d649..ff98d94c1 100644 --- a/lib/pure/asyncftpclient.nim +++ b/lib/pure/asyncftpclient.nim @@ -82,7 +82,7 @@ proc connect*(ftp: AsyncFtpClient) {.async.} = # Handle 220 messages from the server assertReply(reply, "220") - while reply.continuesWith("-", 3): # handle multiline 220 message + while reply[3] == "-": # handle multiline 220 message assertReply(reply, "220") reply = await ftp.expectReply() diff --git a/lib/pure/ftpclient.nim b/lib/pure/ftpclient.nim index 301ca227a..2644fc010 100644 --- a/lib/pure/ftpclient.nim +++ b/lib/pure/ftpclient.nim @@ -271,7 +271,7 @@ proc connect*[T](ftp: FtpBase[T]) = # Handle 220 messages from the server assertReply ftp.expectReply(), "220" - while reply.continuesWith("-", 3): # handle multiline 220 message + while reply[3] == "-": # handle multiline 220 message assertReply ftp.expectReply(), "220" reply = ftp.expectReply()