summaryrefslogtreecommitdiffstats
path: root/module/plugins/hoster/Ftp.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/hoster/Ftp.py')
-rw-r--r--module/plugins/hoster/Ftp.py62
1 files changed, 27 insertions, 35 deletions
diff --git a/module/plugins/hoster/Ftp.py b/module/plugins/hoster/Ftp.py
index 07169ff2e..22fc5f67a 100644
--- a/module/plugins/hoster/Ftp.py
+++ b/module/plugins/hoster/Ftp.py
@@ -1,40 +1,33 @@
# -*- coding: utf-8 -*-
-"""
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License,
- or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>.
-"""
-from urlparse import urlparse
-from urllib import quote, unquote
import pycurl
import re
+from urllib import quote, unquote
+from urlparse import urlparse
+
from module.plugins.Hoster import Hoster
class Ftp(Hoster):
- __name__ = "Ftp"
- __version__ = "0.41"
- __pattern__ = r'(ftps?|sftp)://(.*?:.*?@)?.*?/.*' # ftp://user:password@ftp.server.org/path/to/file
- __type__ = "hoster"
+ __name__ = "Ftp"
+ __type__ = "hoster"
+ __version__ = "0.46"
+
+ __pattern__ = r'(?:ftps?|sftp)://([\w.-]+(:[\w.-]+)?@)?[\w.-]+(:\d+)?/.+'
+
__description__ = """Download from ftp directory"""
- __author_name__ = ("jeix", "mkaay", "zoidberg")
- __author_mail__ = ("jeix@hasnomail.com", "mkaay@mkaay.de", "zoidberg@mujmail.cz")
+ __license__ = "GPLv3"
+ __authors__ = [("jeix", "jeix@hasnomail.com"),
+ ("mkaay", "mkaay@mkaay.de"),
+ ("zoidberg", "zoidberg@mujmail.cz")]
+
def setup(self):
self.chunkLimit = -1
self.resumeDownload = True
+
def process(self, pyfile):
parsed_url = urlparse(pyfile.url)
netloc = parsed_url.netloc
@@ -42,7 +35,7 @@ class Ftp(Hoster):
pyfile.name = parsed_url.path.rpartition('/')[2]
try:
pyfile.name = unquote(str(pyfile.name)).decode('utf8')
- except:
+ except Exception:
pass
if not "@" in netloc:
@@ -50,37 +43,36 @@ class Ftp(Hoster):
if netloc in servers:
self.logDebug("Logging on to %s" % netloc)
- self.req.addAuth(self.account.accounts[netloc]['password'])
+ self.req.addAuth(self.account.getAccountInfo(netloc)['password'])
else:
- for pwd in pyfile.package().password.splitlines():
- if ":" in pwd:
- self.req.addAuth(pwd.strip())
- break
+ pwd = self.getPassword()
+ if ':' in pwd:
+ self.req.addAuth(pwd)
self.req.http.c.setopt(pycurl.NOBODY, 1)
try:
- response = self.load(pyfile.url)
+ res = self.load(pyfile.url)
except pycurl.error, e:
- self.fail("Error %d: %s" % e.args)
+ self.fail(_("Error %d: %s") % e.args)
self.req.http.c.setopt(pycurl.NOBODY, 0)
self.logDebug(self.req.http.header)
- m = re.search(r"Content-Length:\s*(\d+)", response)
+ m = re.search(r"Content-Length:\s*(\d+)", res)
if m:
pyfile.size = int(m.group(1))
self.download(pyfile.url)
else:
- #Naive ftp directory listing
+ #Naive ftp directory listing
if re.search(r'^25\d.*?"', self.req.http.header, re.M):
pyfile.url = pyfile.url.rstrip('/')
pkgname = "/".join(pyfile.package().name, urlparse(pyfile.url).path.rpartition('/')[2])
pyfile.url += '/'
self.req.http.c.setopt(48, 1) # CURLOPT_DIRLISTONLY
- response = self.load(pyfile.url, decode=False)
- links = [pyfile.url + quote(x) for x in response.splitlines()]
+ res = self.load(pyfile.url, decode=False)
+ links = [pyfile.url + quote(x) for x in res.splitlines()]
self.logDebug("LINKS", links)
self.core.api.addPackage(pkgname, links)
else:
- self.fail("Unexpected server response")
+ self.fail(_("Unexpected server response"))