~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

  • Committer: Jelmer Vernooij
  • Date: 2005-11-04 17:26:05 UTC
  • mfrom: (1185.16.146)
  • mto: (1185.33.1)
  • mto: This revision was merged to the branch mainline in revision 1509.
  • Revision ID: jelmer@samba.org-20051104172605-9288f261492667fd
MergeĀ fromĀ Martin

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
    Transport implementation for SFTP access.
88
88
    """
89
89
 
90
 
    _url_matcher = re.compile(r'^sftp://(.*@)?(.*?)(:\d+)?(/.*)?$')
 
90
    _url_matcher = re.compile(r'^sftp://([^:@]*(:[^@]*)?@)?(.*?)(:\d+)?(/.*)?$')
91
91
    
92
92
    def __init__(self, base, clone_from=None):
93
93
        assert base.startswith('sftp://')
148
148
                basepath.append(p)
149
149
 
150
150
        path = '/'.join(basepath)
151
 
        if path[0] != '/':
 
151
        if len(path) and path[0] != '/':
152
152
            path = '/' + path
153
153
        return path
154
154
 
364
364
        m = self._url_matcher.match(url)
365
365
        if m is None:
366
366
            raise SFTPTransportError('Unable to parse SFTP URL %r' % (url,))
367
 
        self._username, self._host, self._port, self._path = m.groups()
 
367
        self._username, self._password, self._host, self._port, self._path = m.groups()
368
368
        if self._username is None:
369
369
            self._username = getpass.getuser()
370
370
        else:
371
371
            self._username = self._username[:-1]
 
372
        if self._password:
 
373
            self._password = self._password[1:]
 
374
            self._username = self._username[len(self._password)+1:]
372
375
        if self._port is None:
373
376
            self._port = 22
374
377
        else:
435
438
        if self._try_pkey_auth(transport, paramiko.DSSKey, 'id_dsa'):
436
439
            return
437
440
 
 
441
        if self._password:
 
442
            try:
 
443
                transport.auth_password(self._username, self._password)
 
444
                return
 
445
            except paramiko.SSHException, e:
 
446
                pass
 
447
 
438
448
        # give up and ask for a password
439
449
        password = getpass.getpass('SSH %s@%s password: ' % (self._username, self._host))
440
450
        try: