本文整理汇总了Python中ftplib.FTP_TLS.sendcmd方法的典型用法代码示例。如果您正苦于以下问题:Python FTP_TLS.sendcmd方法的具体用法?Python FTP_TLS.sendcmd怎么用?Python FTP_TLS.sendcmd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ftplib.FTP_TLS
的用法示例。
在下文中一共展示了FTP_TLS.sendcmd方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendPackagesFtp
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import sendcmd [as 别名]
def sendPackagesFtp():
print "---- Send packages by FTP"
global serverFtp
global userFtp
global passFtp
from ftplib import FTP_TLS
ftps = FTP_TLS(serverFtp)
ftps.set_debuglevel(1)
ftps.login(userFtp, passFtp)
ftps.prot_p()
try:
ftps.sendcmd('MKD ' + '/files/' + strProductVer)
except Exception:
print 'Directory already exists'
ftps.cwd('/files/' + strProductVer)
filesListFtp = ftps.nlst()
filesList = os.listdir(packagesPath)
newFilesList = [e for e in filesList if not(e in filesListFtp)]
for fileName in newFilesList:
ftps.storbinary('STOR ' + fileName, open(packagesPath + '\\' + fileName, 'rb'))
ftps.quit()
示例2: connect
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import sendcmd [as 别名]
def connect(velkost_ftp,port):
ftp=FTP_TLS(server,meno2,ps,port)
ftp.prot_p()
ftp.cwd(my_list[2])
print "Posielam subor. Cakajte prosim."
obsah=open(file_to_send, 'rb')
obsah.close()
ftp.storbinary('STOR %s' % file_to_send, open(file_to_send, 'rb'))
obsah.close()
print "Subor odoslany [OK]"
print "Obsah adresara na serveri:"
ftp.retrlines("LIST")
size_ftp=ftp.nlst()
pocet=len(size_ftp)
velkost_ftp_subor=size_ftp[pocet-1] #berie posledne pridany subor zo zoznamu
ftp.sendcmd("TYPE i")
velkost_ftp=ftp.size(velkost_ftp_subor)
ftp.close()
return velkost_ftp
示例3: uploadToFtp
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import sendcmd [as 别名]
def uploadToFtp(fileList, remoteDir, host, user, password):
"""
:type fileList: list
:type remoteDir: basestring
:type host: basestring
:type user: basestring
:type password: basestring
"""
ftps = FTP_TLS(host)
ftps.sendcmd('USER %s' % user)
ftps.sendcmd('PASS %s' % password)
for fileItem in fileList:
fileName = os.path.split(fileItem)[1]
remoteFilePath = os.path.join(remoteDir, fileName)
print('Uploading file [{0}] to ftp at [{1}]'.format(fileName, remoteFilePath))
ftps.storbinary('STOR {0}'.format(remoteFilePath), open(fileItem))
print('Done.')
ftps.quit()
示例4: FTP_TLS
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import sendcmd [as 别名]
# version one:
# may, 05, 2016
# so, super simple thing to log into an ftp, and issue the command you pass
# in the argument
# syntax: ./script <command>
# the idea is to run this from an eggdrop as a trigger, no fluff
from ftplib import FTP_TLS
from sys import argv
filename, argument = argv
ftps = FTP_TLS()
#ftps.set_debuglevel(2) # if you broke something, uncomment this (run it directly, not from eggdrop)
ftps.connect('your.host', '1111') # enter your server and port within the quotes
ftps.login('specialftpuser', 'qwerty') # enter your user and pass within the quotes (remember, not a user with privs)
ftps.prot_p()
ftps.sendcmd('site ' + argument)
# the tcl script i included will take any output from this python and spam
# it into the channel.. set this how you like, or turn it off
# if you're a tcl guru comment this out and make your tcl do the accounce
print "cmd sent, sleeping now zzzz"
ftps.quit()
quit()
示例5: FTP_TLS
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import sendcmd [as 别名]
import os
#Define credentials
user = 'jack'
secret = '123456'
host = '192.168.1.113'
try:
#instantiate FTPS
#ftps = FTP_TLS(host,user,secret)
ftps = FTP_TLS(host)
# TODO check why the next line not work
#See http://stackoverflow.com/questions/10207628/python-module-ftplib-ftp-tls-error-530
#Try TLS Lite or M2Crypto both are FTP/TLS client and server.
#ftps.login(user,secret)
ftps.sendcmd('USER ' + user)
ftps.sendcmd('PASS ' + secret)
print(ftps.getwelcome())
print('CURRENT WORKING DIRECTORY IS:',ftps.pwd())
#Enable data encryption
# TODO solve the encryption problem
#ftps.prot_p()
#define default DIR
d = 'feeds'
#Change to default DIR
ftps.cwd(d)
#Build list of files on servers
l = ftps.nlst()
l.sort()
for i in l:
print(i)
示例6: ServerWatcher
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import sendcmd [as 别名]
#.........这里部分代码省略.........
:param localpath: Absolute local path where the file will be saved
"""
def handleChunk(chunk):
"""
Receives chuncks of data downloaded from the server.
This function is meant to be used as callback for the `retrbinary` method.
:params chunk: Chunk of downloaded bytes to be written into the file
"""
# Simply writes the received data into the file `self.downloading`
self.downloading.write(chunk)
self.download_progress += len(chunk)
self.downloadProgress.emit(self.download_size, self.download_progress)
if localpath is None:
localpath = self.localFromServer(filename)
localdir = os.path.dirname(localpath)
if not os.path.exists(localdir):
# Creates the directory if it doesn't already exists.
os.makedirs(localdir)
print 'Downloading: %s to %s' % (filename, localpath)
try:
with open(localpath, 'wb') as f:
# Opens the file at `localname` which will hold the downloaded file.
# Object attributes regarding download status are updated accordingly.
self.fileEvent.emit(filename)
self.downloading = f
self.download_progress = 0
self.download_size = int(self.ftp.sendcmd('SIZE %s' % filename).split(' ')[-1])
self.ftp.retrbinary('RETR %s' % filename, handleChunk)
print 'Download finished'
# Let's set the same modified time to that on the server.
with File.fromPath(filename) as downloadedfile:
mdate = LocalWatcher.lastModified(localpath)
downloadedfile.localmdate = mdate
downloadedfile.servermdate = mdate
self.setLastModified(filename, mdate)
downloaded = True
except (IOError, OSError):
downloaded = False
self.ioError.emit(localpath)
except (error_reply, error_perm) as ftperr:
print 'Error downloading %s, %s' % (filename, ftperr)
downloaded = False
# TODO: Sometimes the file doesn't complete properly.
# in that case we maybe shouldn't call this?
self.fileEventCompleted.emit()
return downloaded
@Slot(str)
def onUpload(self, filename):
self.uploadQueue.append(filename)
def uploadNext(self):
if len(self.uploadQueue) > 0: