(Arne Babenhauserheide)
2014-03-14: use ftp instead of ftps if the URL starts with ftp://. use ftp instead of ftps if the URL starts with ftp://.
diff --git a/staticsite.py b/staticsite.py --- a/staticsite.py +++ b/staticsite.py @@ -1428,8 +1428,12 @@ def addrepo(ui, repo, target, bookmarks, def upload(ui, repo, target, ftpstring, force): """upload the repo to the FTP server identified by the ftp string.""" + # assume ftps if no prefix was given (security by default). + isftps = not ftpstring.startswith("ftp://") if ftpstring.startswith("ftp://"): ftpstring = ftpstring[len("ftp://"):] + if ftpstring.startswith("ftps://"): + ftpstring = ftpstring[len("ftps://"):] try: user, password = ftpstring.split("@")[0].split(":") serverandpath = "@".join(ftpstring.split("@")[1:]) @@ -1440,10 +1444,13 @@ def upload(ui, repo, target, ftpstring, server = serverandpath.split("/")[0] ftppath = "/".join(serverandpath.split("/")[1:]) timeout = 60 - # TODO: Use FTP instead of FTPS, if the uri is ftp:// + # Use FTP instead of FTPS, if the uri is ftp:// try: - ftp = ftplib.FTP_TLS(server, user, password, "", timeout=timeout) - ftp.prot_p() + if isftps: + ftp = ftplib.FTP_TLS(server, user, password, "", timeout=timeout) + ftp.prot_p() + else: + ftp = ftplib.FTP(server, user, password, "", timeout=timeout) except socket.timeout: ui.warn(_("connection to "), server, _(" timed out after "), timeout, _(" seconds.\n")) return @@ -1570,7 +1577,7 @@ cmdtable = { wrapcmds = { # cmd: generic, target, fixdoc, ppopts, opts 'push': (False, None, False, False, [ - ('', 'staticsite', None, 'show parent svn revision instead'), + ('', 'staticsite', None, 'upload a static site'), ]) } @@ -1605,11 +1612,9 @@ def ftppush(orig, *args, **opts): return orig(*args, **opts) # first create the site at ._site target = "._site" - ftpstring = path.replace("ftp://", "") - ftpstring = path.replace("ftps://", "") # fix the options to fit those of the site command opts["name"] = opts["sitename"] - opts["upload"] = ftpstring + opts["upload"] = path staticsite(ui, repo, target, **opts) return 0 @@ -1683,7 +1688,7 @@ class FTPRepository(peerrepository): raise util.Abort('command findoutgoing unavailable for FTP repositories') -class RepoContainer(object): +class FTPRepoContainer(object): def __init__(self): pass @@ -1695,8 +1700,20 @@ class RepoContainer(object): #context = {} return FTPRepository(ui, url, create) -hg.schemes["ftp"] = RepoContainer() -hg.schemes["ftps"] = RepoContainer() +class FTPSRepoContainer(object): + def __init__(self): + pass + + def __repr__(self): + return '<FTPRepository>' + + def instance(self, ui, url, create): + # Should this use urlmod.url(), or is manual parsing better? + #context = {} + return FTPRepository(ui, url, create) + +hg.schemes["ftp"] = FTPRepoContainer() +hg.schemes["ftps"] = FTPSRepoContainer() def test(): import subprocess as sp