Subject: Allow custom FTP logins.

From: Roel Janssen <[email-masked]>
Date: Mon, 20 Mar 2017 13:10:08 +0100

>From 8536ba69ec3a04930e8a78c8f2b824df3e8c0454 Mon Sep 17 00:00:00 2001
From: Roel Janssen <[email-masked]>
Date: Mon, 20 Mar 2017 12:57:25 +0100
Subject: [PATCH 1/2] ftp-client: Allow custom username and password for FTP
 servers.

* guix/ftp-client.scm (ftp-open): Add username and password arguments.
---
 guix/ftp-client.scm | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/guix/ftp-client.scm b/guix/ftp-client.scm
index 0a179282e..054a00ad7 100644
--- a/guix/ftp-client.scm
+++ b/guix/ftp-client.scm
@@ -121,7 +121,10 @@ seconds to wait for the connection to succeed."
              (raise-error errno)))))
       (connect s sockaddr)))
 
-(define* (ftp-open host #:optional (port "ftp") #:key timeout)
+(define* (ftp-open host #:optional (port "ftp")
+                        #:key timeout
+                              (username "anonymous")
+                              (password "[email-masked]"))
   "Open an FTP connection to HOST on PORT (a service-identifying string,
 or a TCP port number), and return it.
 
@@ -156,7 +159,7 @@ TIMEOUT, an ETIMEDOUT error is raised."
                (if (eqv? code 220)
                    (begin
                      ;;(%ftp-command "OPTS UTF8 ON" 200 s)
-                     (%ftp-login "anonymous" "[email-masked]" s)
+                     (%ftp-login username password s)
                      (%make-ftp-connection s ai))
                    (begin
                      (close s)
-- 
2.11.1

>From e7263ce1d1a242f187c9801b14ea47043f59be8e Mon Sep 17 00:00:00 2001
From: Roel Janssen <[email-masked]>
Date: Mon, 20 Mar 2017 12:59:59 +0100
Subject: [PATCH 2/2] download: Handle username and password properties for FTP
 uris.

guix/build/download.scm (ftp-fetch): Process username and password from a URI.
---
 guix/build/download.scm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/guix/build/download.scm b/guix/build/download.scm
index 36c815c16..f48da7500 100644
--- a/guix/build/download.scm
+++ b/guix/build/download.scm
@@ -241,7 +241,14 @@ and 'guix publish', something like
 (define* (ftp-fetch uri file #:key timeout)
   "Fetch data from URI and write it to FILE.  Return FILE on success.  Bail
 out if the connection could not be established in less than TIMEOUT seconds."
-  (let* ((conn (ftp-open (uri-host uri) #:timeout timeout))
+  (let* ((userinfo (string-split (uri-userinfo uri) #\:))
+         (username (if (and (> (length userinfo) 0)
+                            (not (string= (car userinfo) "")))
+                       (car userinfo) #f))
+         (password (if (> (length userinfo) 1) (cadr userinfo) #f))
+         (conn (ftp-open (uri-host uri) #:timeout timeout
+                                        #:username username
+                                        #:password password))
          (size (false-if-exception (ftp-size conn (uri-path uri))))
          (in   (ftp-retr conn (basename (uri-path uri))
                          (dirname (uri-path uri)))))
-- 
2.11.1

Dear guix,

These two patches enable the handling of usernames and passwords in a
FTP uri.

Kind regards,
Roel Janssen