Ejemplo n.º 1
0
    def _xdir(self, returnlist=False):
        if self.ftp == None:
            self.send_log_message('Not connected')
            return False

        list_command = "LIST"

        if self.system.find("VMS") >= 0 or self.system.find("MultiNet Unix Emulation") >= 0:
            list_command = "LIST"

        lines = []
        with redirect_stdout(self.out):
            try:
                ret = self.ftp.retrlines(list_command, lines.append)
                lines = self.encode_lines(lines)
                files = parse_list(lines)
                if returnlist:
                    return files
                if files:
                    self.update_file_list(files)
                #if 'MLSD' in self.features:
                #    self.ftp.retrlines('MLSD', self.dump)
            except error_perm as err:
                self.out.write(str(err))
                return False
Ejemplo n.º 2
0
    def _open(self, remote_host, remote_port, user, passwd):
        self.ftp = FTP()
        self.ftp.set_debuglevel(1)

        with redirect_stdout(self.out):
            try:
                self.ftp.connect(remote_host, remote_port, 20)
            except:
                self.out.write('*ERROR*' + str(sys.exc_info()[1]))
                self.ftp = None
                return False
            try:
                self.ftp.login(user, passwd)
                self.connected = True
            except:
                self.ftp = None
                return False
            try:
                #self.ftp.sendcmd('cd []')
                self.system = self.ftp.sendcmd('SYST')
            except:
                pass
            try:
                self.features = self.parseFeatures(self.ftp.sendcmd('FEAT'), '211')
            except:
                pass
            return True
Ejemplo n.º 3
0
 def _chmod(self, path, mode):
     with redirect_stdout(self.out):
         try:
             self.parseFeatures(self.ftp.sendcmd('SITE CHMOD %s %s' % (mode, self.encode_cmd(path))), '200')
             return True
         except error_perm as err:
             return False
Ejemplo n.º 4
0
 def _rename(self, src, dst):
     with redirect_stdout(self.out):
         try:
             self.ftp.rename(self.encode_cmd(src), self.encode_cmd(dst))
             return True
         except error_perm as err:
             return False
Ejemplo n.º 5
0
 def _get_init(self, filename):
     with redirect_stdout(self.out):
         try:
             self.ftp.voidcmd('TYPE I')
             self.datasocket = self.ftp.transfercmd('RETR ' + self.encode_cmd(filename))
             return True
         except error_perm as err:
             return False
Ejemplo n.º 6
0
 def _put_init(self, filename):
     #self.filehandle = open(os.path.join(self.currentdir, filename), 'w')
     with redirect_stdout(self.out):
         try:
             self.ftp.voidcmd('TYPE I')
             self.datasocket = self.ftp.transfercmd('STOR ' + self.encode_cmd(filename))
             return True
         except error_perm as err:
             return False
Ejemplo n.º 7
0
 def _put_end(self):
     with redirect_stdout(self.out):
         try:
             self.datasocket.close()
             self.ftp.voidresp()
             self.datasocket = None
             self._xdir()
             return True
         except error_perm as err:
             return False
Ejemplo n.º 8
0
 def _cwd(self, _path):
     if self.ftp is None:
         self.send_log_message('Not connected')
         return False
     with redirect_stdout(self.out):
         try:
             self.ftp.cwd(self.encode_cmd(_path))
             return True
         except error_perm as err:
             #self.out.write(str(err))
             return False
         except:
             self.send_log_message(['error', 'ftp.py: %s' % sys.exc_info()[1] + '\n'])
             return False
Ejemplo n.º 9
0
    def _pwd(self):
        if self.ftp is None:
            self.send_log_message('Not connected')
            return False

        with redirect_stdout(self.out):
            try:
                pwd = self.ftp.pwd()
                pwd = self.encode_resp(pwd)
                self.current_dir = pwd
                self.pwd_received(pwd)
                return True
            except error_perm as err:
                self.out.write(str(err))
                return False
Ejemplo n.º 10
0
 def _rmdir(self, dirname):
     with redirect_stdout(self.out):
         try:
             _files = []
             self.traverse(dirname, _files)
             _files.reverse()
             self._cwd(self.current_dir)
             for f in _files:
                 #print(f.rel_path + '/' + f.filename)
                 if f.isdir:
                     self.ftp.rmd(self.encode_cmd(f.filename))
                 else:
                     self.ftp.delete(self.encode_cmd(f.filename))
             self.ftp.rmd(self.encode_cmd(dirname))
         except error_perm as err:
             return False
Ejemplo n.º 11
0
 def _delete(self, filename):
     with redirect_stdout(self.out):
         try:
             self.ftp.delete(self.encode_cmd(filename))
         except error_perm as err:
             return False
Ejemplo n.º 12
0
 def _mkdir(self, _path):
     with redirect_stdout(self.out):
         try:
             self.ftp.mkd(self.encode_cmd(_path))
         except error_perm as err:
             return False