From fc749b5de1b7de06deae8d0159100ab1d19ee8f8 Mon Sep 17 00:00:00 2001 From: Olivier Martin Date: Fri, 16 Oct 2015 13:47:39 +0100 Subject: [PATCH 1/2] Displayed a more comprehensive error message if the base directory does not exist Some FTP servers limit the access to a sub-directory of the filesystem while other FTP servers expose the entire filesystem and could also start the FTP session to the user home directory. In this case the base directory is related to the root filesystem and not related to the start of the TFP session. This error message highlights the given base directory and the directory where the FTP session started. --- git-ftp.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/git-ftp.py b/git-ftp.py index f4453ee..bc535e6 100755 --- a/git-ftp.py +++ b/git-ftp.py @@ -145,7 +145,10 @@ def main(): raise FtpSslNotSupported("Python is too old for FTP SSL. Try using Python 2.7 or later.") else: ftp = ftplib.FTP(options.ftp.hostname, options.ftp.username, options.ftp.password) - ftp.cwd(base) + try: + ftp.cwd(base) + except ftplib.error_perm: + raise ValueError("FTP base directory '%s' does not exist on this server (note: the server session starts at '%s')" % (base, ftp.pwd())) # Check revision hash = options.revision From 1a037cdde0b5ea674b445052b2ce117bc64eb777 Mon Sep 17 00:00:00 2001 From: Olivier Martin Date: Fri, 16 Oct 2015 21:17:31 +0100 Subject: [PATCH 2/2] Force the base directory to be an absolute path It is required 'base' variable contains an absolute path for the subsequent steps. --- git-ftp.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/git-ftp.py b/git-ftp.py index bc535e6..2548b84 100755 --- a/git-ftp.py +++ b/git-ftp.py @@ -145,6 +145,11 @@ def main(): raise FtpSslNotSupported("Python is too old for FTP SSL. Try using Python 2.7 or later.") else: ftp = ftplib.FTP(options.ftp.hostname, options.ftp.username, options.ftp.password) + + # Make the base directory an absolute path - it is required for the subsequent steps + if base[0] != '/': + base = os.path.join(ftp.pwd(), base) + try: ftp.cwd(base) except ftplib.error_perm: