2001-03-15 01:19:35 +00:00
|
|
|
"""Handle FTP links"""
|
2001-05-23 21:20:44 +00:00
|
|
|
# Copyright (C) 2000,2001 Bastian Kleineidam
|
2001-03-15 01:19:35 +00:00
|
|
|
#
|
2001-05-23 21:20:44 +00:00
|
|
|
# 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 2 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
2001-03-15 01:19:35 +00:00
|
|
|
#
|
2001-05-23 21:20:44 +00:00
|
|
|
# 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.
|
2001-03-15 01:19:35 +00:00
|
|
|
#
|
2001-05-23 21:20:44 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2000-11-11 00:38:04 +00:00
|
|
|
|
2002-02-24 12:29:35 +00:00
|
|
|
import ftplib, linkcheck
|
2000-06-11 19:33:01 +00:00
|
|
|
from UrlData import UrlData,ExcList
|
2000-05-28 23:49:42 +00:00
|
|
|
|
2000-06-11 19:33:01 +00:00
|
|
|
ExcList.extend([
|
|
|
|
|
ftplib.error_reply,
|
|
|
|
|
ftplib.error_temp,
|
|
|
|
|
ftplib.error_perm,
|
|
|
|
|
ftplib.error_proto,
|
|
|
|
|
])
|
2000-02-26 10:24:46 +00:00
|
|
|
|
2002-05-04 13:27:02 +00:00
|
|
|
class FtpUrlData (UrlData):
|
2000-11-09 12:02:38 +00:00
|
|
|
"""
|
2002-05-04 13:27:02 +00:00
|
|
|
Url link with ftp scheme.
|
2000-11-09 12:02:38 +00:00
|
|
|
"""
|
2001-12-10 13:51:07 +00:00
|
|
|
|
2002-05-04 13:27:02 +00:00
|
|
|
def checkConnection (self):
|
|
|
|
|
_user, _password = self._getUserPassword()
|
2000-06-19 08:43:18 +00:00
|
|
|
if _user is None or _password is None:
|
2002-02-24 12:29:35 +00:00
|
|
|
raise linkcheck.error, linkcheck._("No user or password found")
|
2001-09-18 19:16:20 +00:00
|
|
|
try:
|
|
|
|
|
self.urlConnection = ftplib.FTP(self.urlTuple[1], _user, _password)
|
|
|
|
|
except EOFError:
|
2002-02-24 12:29:35 +00:00
|
|
|
raise linkcheck.error, linkcheck._("Remote host has closed connection")
|
2000-02-26 10:24:46 +00:00
|
|
|
info = self.urlConnection.getwelcome()
|
|
|
|
|
if not info:
|
|
|
|
|
self.closeConnection()
|
2002-02-24 12:29:35 +00:00
|
|
|
raise linkcheck.error, linkcheck._("Got no answer from FTP server")
|
2000-02-26 10:24:46 +00:00
|
|
|
self.setInfo(info)
|
2001-12-10 13:51:07 +00:00
|
|
|
|
|
|
|
|
|
2002-05-04 13:27:02 +00:00
|
|
|
def closeConnection (self):
|
2000-02-26 10:24:46 +00:00
|
|
|
try: self.urlConnection.quit()
|
|
|
|
|
except: pass
|
|
|
|
|
self.urlConnection = None
|