120
120
in base url at transport creation time.
122
122
if credentials is None:
123
password = self._password
123
user, password = self._user, self._password
125
password = credentials
125
user, password = credentials
127
auth = config.AuthenticationConfig()
129
user = auth.get_user('ftp', self._host, port=self._port)
131
# Default to local user
132
user = getpass.getuser()
127
134
mutter("Constructing FTP instance against %r" %
128
((self._host, self._port, self._user, '********',
135
((self._host, self._port, user, '********',
129
136
self.is_active),))
131
138
connection = ftplib.FTP()
132
139
connection.connect(host=self._host, port=self._port)
133
if self._user and self._user != 'anonymous' and \
140
if user and user != 'anonymous' and \
134
141
password is None: # '' is a valid password
135
auth = config.AuthenticationConfig()
136
password = auth.get_password('ftp', self._host, self._user,
142
password = auth.get_password('ftp', self._host, user,
138
connection.login(user=self._user, passwd=password)
144
connection.login(user=user, passwd=password)
139
145
connection.set_pasv(not self.is_active)
140
146
except ftplib.error_perm, e:
141
147
raise errors.TransportError(msg="Error setting up connection:"
142
148
" %s" % str(e), orig_error=e)
143
return connection, password
149
return connection, (user, password)
145
151
def _reconnect(self):
146
152
"""Create a new connection with the previously used credentials"""