summaryrefslogtreecommitdiffstats
path: root/module/plugins/hoster/Ftp.py
diff options
context:
space:
mode:
authorGravatar zoidberg10 <zoidberg@mujmail.cz> 2012-09-24 23:54:50 +0200
committerGravatar zoidberg10 <zoidberg@mujmail.cz> 2012-09-24 23:54:50 +0200
commitb65c4091d5c5e793d8a9df17a46657d45c3a1292 (patch)
tree40a420e5213d28634b75408059a2dc3687e461d1 /module/plugins/hoster/Ftp.py
parentupdate hellshare/hellspy patterns (diff)
downloadpyload-b65c4091d5c5e793d8a9df17a46657d45c3a1292.tar.xz
multihosters - closed #618, store http/ftp accounts, add uptobox.com premium
Diffstat (limited to 'module/plugins/hoster/Ftp.py')
-rw-r--r--module/plugins/hoster/Ftp.py73
1 files changed, 62 insertions, 11 deletions
diff --git a/module/plugins/hoster/Ftp.py b/module/plugins/hoster/Ftp.py
index 7c2af85ed..3bda3b32e 100644
--- a/module/plugins/hoster/Ftp.py
+++ b/module/plugins/hoster/Ftp.py
@@ -17,24 +17,75 @@
@author: jeix
@author: mkaay
"""
+from urlparse import urlparse, urljoin
+from urllib import quote, unquote
+import pycurl, re
from module.plugins.Hoster import Hoster
-
+from module.network.HTTPRequest import BadHeader
class Ftp(Hoster):
__name__ = "Ftp"
- __version__ = "0.31"
+ __version__ = "0.41"
__pattern__ = r'(ftps?|sftp)://(.*?:.*?@)?.*?/.*' # ftp://user:password@ftp.server.org/path/to/file
__type__ = "hoster"
__description__ = """A Plugin that allows you to download from an from an ftp directory"""
- __author_name__ = ("jeix", "mkaay")
- __author_mail__ = ("jeix@hasnomail.com", "mkaay@mkaay.de")
+ __author_name__ = ("jeix", "mkaay", "zoidberg")
+ __author_mail__ = ("jeix@hasnomail.com", "mkaay@mkaay.de", "zoidberg@mujmail.cz")
- def process(self, pyfile):
- pyfile.name = self.pyfile.url.rpartition('/')[2]
-
+ def setup(self):
self.chunkLimit = -1
- self.resumeDownload = True
-
- self.download(pyfile.url)
-
+ self.resumeDownload = True
+
+ def process(self, pyfile):
+ parsed_url = urlparse(pyfile.url)
+ netloc = parsed_url.netloc
+
+ pyfile.name = parsed_url.path.rpartition('/')[2]
+ try:
+ pyfile.name = unquote(str(pyfile.name)).decode('utf8')
+ except:
+ pass
+
+ if not "@" in netloc:
+ servers = [ x['login'] for x in self.account.getAllAccounts() ] if self.account else []
+
+ if netloc in servers:
+ self.logDebug("Logging on to %s" % netloc)
+ self.req.addAuth(self.account.accounts[netloc]["password"])
+ else:
+ for pwd in pyfile.package().password.splitlines():
+ if ":" in pwd:
+ self.req.addAuth(pwd.strip())
+ break
+
+ self.req.http.c.setopt(pycurl.NOBODY, 1)
+
+ try:
+ response = self.load(pyfile.url)
+ except pycurl.error, e:
+ self.fail("Error %d: %s" % e.args)
+
+ self.req.http.c.setopt(pycurl.NOBODY, 0)
+ self.logDebug(self.req.http.header)
+
+ found = re.search(r"Content-Length:\s*(\d+)", response)
+ if found:
+ pyfile.size = int(found.group(1))
+ self.download(pyfile.url)
+ else:
+ #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() ]
+ self.logDebug("LINKS", links)
+ self.core.api.addPackage(pkgname, links, 1)
+ #self.core.files.addLinks(links, pyfile.package().id)
+ else:
+ self.fail("Unexpected server response")
+
+ \ No newline at end of file