当前位置: 首页>>代码示例>>Python>>正文


Python FTP_TLS.set_pasv方法代码示例

本文整理汇总了Python中ftplib.FTP_TLS.set_pasv方法的典型用法代码示例。如果您正苦于以下问题:Python FTP_TLS.set_pasv方法的具体用法?Python FTP_TLS.set_pasv怎么用?Python FTP_TLS.set_pasv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ftplib.FTP_TLS的用法示例。


在下文中一共展示了FTP_TLS.set_pasv方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: connexionftp

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import set_pasv [as 别名]
def connexionftp(adresseftp, nom, mdpasse, passif):
	"""connexion au serveur ftp et ouverture de la session
	   - adresseftp: adresse du serveur ftp
	   - nom: nom de l'utilisateur enregistré ('anonymous' par défaut)
	   - mdpasse: mot de passe de l'utilisateur ('[email protected]' par défaut)
	   - passif: active ou désactive le mode passif (True par défaut)
	   retourne la variable 'ftplib.FTP' après connexion et ouverture de session
	"""
	try:
		verbose('Attente connexion FTP .....')
		if modeSSL:
			ftp = FTP_TLS()
			ftp.connect(adresseftp, 21)
			ftp.login(nom, mdpasse)
			ftp.prot_p()
			ftp.set_pasv(passif)
		else:
			ftp = (ftplib.FTP(adresseftp, nom, mdpasse))
			
		ftp.cwd(destination)
		verbose ('Destination : '+destination)
		verbose('Connexion FTP OK')
		etat = ftp.getwelcome()
		verbose("Etat : "+ etat) 
		return ftp
	except:
		verbose('Connexion FTP impossible', True)
		suppressionDossierTemp(dossierTemporaireFTP)
		sys.exit()
开发者ID:Michelgard,项目名称:backup_serveur,代码行数:31,代码来源:backupserveurFTP.py

示例2: Push

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import set_pasv [as 别名]
def Push( FtpServer, Username, Password, uploadlist = FilesToPut, port = 21, passive = False, StartTls = False ):
	print "Login to %s:%s using %s:%s (%s%s)"%(FtpServer, port, Username, 'xxx', 
				'passive' if passive else 'active', 
				'/tls' if StartTls else '')

	if StartTls:
		ftp = FTP_TLS()
	else:
		ftp = FTP()
	
	#ftp.set_debuglevel(2)

	ftp.connect( FtpServer, port )
	ftp.login( Username, Password )                     # user anonymous, passwd [email protected]
	ftp.set_pasv( passive )

	if StartTls:
		ftp.prot_p()	    

	for f in uploadlist:
		print "uploading %s"%f		
		fp = open( f, 'rb')
		ftp.storbinary('STOR %s'%os.path.basename(f), fp)     # send the file

	ftp.quit()
开发者ID:rodsur,项目名称:ProItsScripts,代码行数:27,代码来源:PushToFtp.py

示例3: ftpUpload

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import set_pasv [as 别名]
def ftpUpload(filename):
    from ftplib import FTP_TLS
    import os
    
    ftps = FTP_TLS()
    ftps.connect('pwcrack.init6.me', '21')
    ftps.auth()
    ftps.login('DC214', 'passwordcrackingcontest')
    ftps.prot_p()
    ftps.set_pasv(True)
    local_file = open(filename, 'rb')
    ftps.storbinary('STOR '+filename, local_file)
开发者ID:initiate6,项目名称:pwcrack,代码行数:14,代码来源:FTPupload.py

示例4: Push

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import set_pasv [as 别名]
def Push( FtpServer, Username, Password, uploadlist = FilesToPut, port = 21, passive = False, StartTls = False, Sftp = False ):
        print "Login to %s:%s using %s:%s (%s%s)"%(FtpServer, port, Username, 'xxx', 
				'passive' if passive else 'active', 
				'/tls' if StartTls else '')
                
        if Sftp:
            paramiko.util.log_to_file('/tmp/paramiko.log')
            transport = paramiko.Transport((FtpServer,int(port)))
            transport.connect(username = Username, password = Password)
            sftp = paramiko.SFTPClient.from_transport(transport)
            
            print "Uploading file"
  
            filepath = '../php/basedata.php'
            localpath = 'basedata.php'
            sftp.put(filepath, localpath)
            sftp.close()
            transport.close()

        else:
            if StartTls:
                ftp = FTP_TLS()
	        else:
                ftp = FTP()

            ftp.connect( FtpServer, port )
	    ftp.login( Username, Password)
	    ftp.set_pasv( passive )
                
	        if StartTls:
                ftp.prot_p()

            for f in uploadlist:
            print "uploading %s"%f
            fp = open( f, 'rb')
            ftp.storbinary('STOR %s'%os.path.basename(f), fp)     # send the file
            
            ftp.quit()

if __name__ == "__main__":
	if len(sys.argv) < 5:
		print >> sys.stderr, "usage %s <server> <port> <username> <password>"%sys.argv[0]
		exit( 1 )

	FtpServer = sys.argv[1]
	Port = sys.argv[2]
	Username = sys.argv[3]
	Passwd = sys.argv[4]

	Push( FtpServer, Username, Passwd, port = Port )
	print >> sys.stderr, "Done"
开发者ID:Sifungurux,项目名称:ProItsScripts,代码行数:53,代码来源:PushToFtp.py

示例5: ftpDownload

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import set_pasv [as 别名]
def ftpDownload(filename):
    from ftplib import FTP_TLS
    import os
    
    ftps = FTP_TLS()
    ftps.connect('pwcrack.init6.me', '21')
    ftps.auth()
    ftps.login('DC214', 'passwordcrackingcontest')
    ftps.prot_p()
    ftps.set_pasv(True)
    local_filename = filename
    with open(local_filename, 'wb') as f:
        def callback(data):
            f.write(data)
        ftps.retrbinary('RETR %s' % filename, callback)
开发者ID:initiate6,项目名称:pwcrack,代码行数:17,代码来源:FTPdownload.py

示例6: ftpUpload

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import set_pasv [as 别名]
def ftpUpload(filename, system):
    
    from ftplib import FTP_TLS
    import os
    if os.path.isfile(filename):
        
        zipFilename = compressit(filename, system)
        
        ftps = FTP_TLS()
        ftps.connect('pwcrack.init6.me', '21')
        ftps.auth()
        ftps.login('DC214', 'passwordcrackingcontest')
        ftps.prot_p()
        ftps.set_pasv(True)
        local_file = open(zipFilename, 'rb')
        ftps.storbinary('STOR '+zipFilename, local_file)

        print "file %s has been uploaded." % zipFilename
        return True 
开发者ID:initiate6,项目名称:pwcrack,代码行数:21,代码来源:client.py

示例7: ftpDownload

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import set_pasv [as 别名]
def ftpDownload(filename, system):
    from ftplib import FTP_TLS
    import os
    
    ftps = FTP_TLS()
    ftps.connect('pwcrack.init6.me', '21')
    ftps.auth()
    ftps.login('DC214', 'passwordcrackingcontest')
    ftps.prot_p()
    ftps.set_pasv(True)
    local_filename = filename
    with open(local_filename, 'wb') as f:
        def callback(data):
            print "Downloading %s ..." % filename
            f.write(data)
        ftps.retrbinary('RETR %s' % filename, callback)
    f.close()

    file_extension = str(filename.rsplit('.')[2])
    
    if file_extension == '7z':
        status = decompressit(local_filename, system)
        if status:
            print "file %s has been downloaded." % local_filename
开发者ID:initiate6,项目名称:pwcrack,代码行数:26,代码来源:setup.py

示例8: Sftpimpl

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import set_pasv [as 别名]
class Sftpimpl(Ftpimpl):
	def __init__(self):
		self.log = ProcessLogger()
	def connectFTP(self,host='',port='',uname='',upass='',ssh_host_key='',acv_pcv=''):
		if host=='' or port=='' or uname=='' or upass=='':
			raise FTP_ERROR('Oops: Blank config parameters, Please dont leave any config parameter blank')
		self.host = host
		log_id = self.log.processlog(logid=0,f1=False,f2=False,hostnm=host,up_dw='login',typ='new',status='Pending',result='trying to connect...')
		hostStr = '%s:%s' %(host,port)
		usrHostStr = '%[email protected]%s' %(uname,hostStr)
		try:
			self.ftp = FTP_TLS(hostStr)
			if acv_pcv == 'Active':
				self.ftp.set_pasv(False)
			elif acv_pcv == 'Passive':
				self.ftp.set_pasv(True)
				
			self.ftp.login(uname,upass)
			self.ftp.prot_p()
			return_msg = self.ftp.getwelcome()
			self.log.processlog(logid=log_id,f1=False,f2=False,hostnm=host,up_dw='login',typ='edit',status='Done',result=return_msg)
		except Exception as e:
			self.log.processlog(logid=log_id,f1=False,f2=False,hostnm=host,up_dw='login',typ='edit',status='Failed',result=str(e))
			raise FTP_ERROR('Connection error: Reasons \n\n(Internet connection)\n(Remote server down)\n(Config settings) ')
开发者ID:raapchikftp,项目名称:raapchikftp,代码行数:26,代码来源:sftpimpl.py

示例9: __init__

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import set_pasv [as 别名]
class FTPES:
    def __init__(self, host, port=None, username=None, password=None, remote_path=None, absolute_zipfile_path=None):
        """
        This is a helper class to manage the FTP commands from the ftplib.

        @param host: The host for the connection.
        @type host: String
        @param port: The post for the connection.
        @type port: Integer
        @param username: The username for the connection. Leave blank to use "anonymous".
        @type username: String
        @param password: The password for the connection. Leave empty for none.
        @type password: String
        @param remote_path: The remote path of the server in which the zip file should be uploaded. If the path does not
                            exists, it will be created (recursive).
        @type remote_path: String
        @param absolute_zipfile_path: The absolute LOCAL filepath of the zip file.
        @type absolute_zipfile_path: String
        """
        self.ftps = None
        self._host = host
        self._port = port
        self._username = username
        self._password = password
        self._remote_path = remote_path
        self._absolute_zipfile_path = absolute_zipfile_path
        self._bytesWritten = 0;
        self._totalFileSize = os.path.getsize(self._absolute_zipfile_path)
        self._uploadCallback = None
        self._currentProgress = 0

        # make the remote path relative if it isnt absolute or relative yet
        if self._remote_path is not None and self._remote_path.startswith(
                '.') is False and self._remote_path.startswith('/') is False:
            self._remote_path = './' + self._remote_path

        if self._username is None:
            self._username = 'anonymous'

        if self._port is None:
            self._port = 22

    def connect(self):
        """
        Try to connect to the FTP server.
        Raise an error if something went wrong.
        """
        try:
            self.ftps = FTP_TLS()
            self.ftps.set_pasv(True)
            self.ftps.connect(self._host, self._port)
        except socket.gaierror:
            raise

    def login(self):
        """
        Try to login in on the FTP server.
        Raise an error if something went wrong.
        """
        try:
            self.ftps.login(self._username, self._password)
            self.ftps.prot_p()
        except ftplib.error_perm:
            raise

    def cwd(self):
        """
        Try to switch the working directory on the FTP server (if set in the settings).
        If the path does not exist, it will be created.
        """
        if self._remote_path is not None:
            try:
                self.ftps.cwd(self._remote_path)
            except ftplib.error_perm:
                self.create_directory_tree(self._remote_path)
            except IOError:
                raise

    def create_directory_tree(self, current_directory):
        """
        Helper function to create the remote path.

        @param current_directory: The current working directory.
        @type current_directory: String
        """
        if current_directory is not "":
            try:
                self.ftps.cwd(current_directory)
            except ftplib.error_perm:
                self.create_directory_tree("/".join(current_directory.split("/")[:-1]))
                self.ftps.mkd(current_directory)
                self.ftps.cwd(current_directory)
            except IOError:
                raise

    def upload(self, callback=None):
        """
        The upload function.

        @param callback: The callback function for the upload progress.
#.........这里部分代码省略.........
开发者ID:pixel-shock,项目名称:dropzone-ftpes-upload,代码行数:103,代码来源:ftpes.py


注:本文中的ftplib.FTP_TLS.set_pasv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。