def connectOrDisconnect(self): """ .. py:attribute:: connectOrDisconnect() :rtype: UNKNOWN .. note:: .. todo:: """ if self.ftp: self.ftp.abort() self.ftp.deleteLater() self.ftp = None self.fileList.setEnabled(False) self.cdToParentButton.setEnabled(False) self.downloadButton.setEnabled(False) self.connectButton.setEnabled(True) self.connectButton.setText("Connect") self.setCursor(QtCore.Qt.ArrowCursor) return self.setCursor(QtCore.Qt.WaitCursor) self.ftp = QtNetwork.QFtp(self) self.ftp.commandFinished.connect(self.ftpCommandFinished) self.ftp.listInfo.connect(self.addToList) self.ftp.dataTransferProgress.connect(self.updateDataTransferProgress) self.fileList.clear() self.currentPath = '' self.isDirectory.clear() url = QtCore.QUrl(self.ftpServerLabel.text()) if not url.isValid() or url.scheme().lower() != 'ftp': self.ftp.connectToHost(self.ftpServerLabel.text(), 21) self.ftp.login() else: self.ftp.connectToHost(url.host(), url.port(21)) user_name = url.userName() if user_name: try: user_name = bytes(user_name, encoding='utf-8') except: pass self.ftp.login(QtCore.QUrl.fromPercentEncoding(user_name), url.password()) else: self.ftp.login() if url.path(): self.ftp.cd(url.path()) self.fileList.setEnabled(True) self.connectButton.setEnabled(False) self.connectButton.setText("Disconnect") self.statusLabel.setText("Connecting to ftp server %s..." % self.ftpServerLabel.text())
def connectOrDisconnect(self): if self.ftp: self.ftp.abort() self.ftp.deleteLater() self.ftp = None self.fileList.setEnabled(False) self.cdToParentButton.setEnabled(False) self.downloadButton.setEnabled(False) self.connectButton.setEnabled(True) self.connectButton.setText(u"Соединение") self.setCursor(QtCore.Qt.ArrowCursor) return self.setCursor(QtCore.Qt.WaitCursor) self.ftp = QtNetwork.QFtp(self) self.ftp.commandFinished.connect(self.ftpCommandFinished) self.ftp.listInfo.connect(self.addToList) self.ftp.dataTransferProgress.connect(self.updateDataTransferProgress) self.fileList.clear() self.currentPath = '' self.isDirectory.clear() url = QtCore.QUrl(self.ftpServerLineEdit.text()) if not url.isValid() or url.scheme().lower() != 'ftp': self.ftp.connectToHost(self.ftpServerLineEdit.text(), 21) self.ftp.login() else: self.ftp.connectToHost(url.host(), url.port(21)) user_name = url.userName() if user_name: try: # Python v3. user_name = bytes(user_name, encoding='latin1') except: # Python v2. pass self.ftp.login(QtCore.QUrl.fromPercentEncoding(user_name), url.password()) else: self.ftp.login() if url.path(): self.ftp.cd(url.path()) self.fileList.setEnabled(True) self.connectButton.setEnabled(False) self.connectButton.setText(u"Отключение") self.statusLabel.setText(u"Соединяюсь с FTP сервером %s..." % self.ftpServerLineEdit.text())
def run(self, Form): Form.setObjectName(_fromUtf8("Form")) Form.resize(371, 236) Form.setWindowIcon(QtGui.QIcon('car.png')) self.ftpClient = QtNetwork.QFtp() self.ftpClient.connectToHost(QtCore.QString('192.168.0.4'), port=2121) self.ftpClient.login('FTPuser', '123') self.ftpClient.list() self.progressBar = QtGui.QProgressBar(Form) self.progressBar.setGeometry(QtCore.QRect(0, 210, 381, 23)) self.progressBar.setProperty("value", 0) self.progressBar.setObjectName(_fromUtf8("progressBar")) self.uploadButton = QtGui.QPushButton(Form) self.uploadButton.setGeometry(QtCore.QRect(0, 180, 81, 31)) self.uploadButton.setObjectName(_fromUtf8("uploadButton")) self.downloadButton = QtGui.QPushButton(Form) self.downloadButton.setGeometry(QtCore.QRect(290, 180, 81, 31)) self.downloadButton.setObjectName(_fromUtf8("downloadButton")) self.treeWidget = QtGui.QTreeWidget(Form) self.treeWidget.setGeometry(QtCore.QRect(0, 0, 371, 181)) self.treeWidget.setObjectName(_fromUtf8("treeWidget")) self.label = QtGui.QLabel(Form) self.label.setGeometry(QtCore.QRect(120, 190, 111, 16)) self.label.setObjectName(_fromUtf8("label")) self.retranslateUi(Form) QtCore.QObject.connect(self.ftpClient, QtCore.SIGNAL("listInfo(QUrlInfo)"), Form.addToList) QtCore.QObject.connect(self.ftpClient, QtCore.SIGNAL("commandFinished(int,bool)"), Form.ftpCommandFinished) QtCore.QObject.connect(self.uploadButton, QtCore.SIGNAL(_fromUtf8("clicked()")), Form.upload_file) QtCore.QObject.connect(self.downloadButton, QtCore.SIGNAL(_fromUtf8("clicked()")), Form.download_file) QtCore.QObject.connect( self.ftpClient, QtCore.SIGNAL("dataTransferProgress(qint64,qint64)"), Form.updateDataTransferProgress) QtCore.QMetaObject.connectSlotsByName(Form) self.i = 1 self.filenamels = []
def connectOrDisconnect(self): """ Connecting to and disconnecting from FTP host. .. py:attribute:: connectOrDisconnect() :rtype: UNKNOWN .. note:: .. todo:: """ if not self.ftp: print('create new FTP connection') self.ftp = QtNetwork.QFtp(self) self.setCursor(QtCore.Qt.WaitCursor) self.ftp.commandFinished.connect(self.ftpCommandFinished) self.ftp.listInfo.connect(self.addToList) self.ftp.dataTransferProgress.connect(self.updateDataTransferProgress) self.fileList.clear() self.currentPath = '' self.isDirectory.clear() url = QtCore.QUrl(self.root) if not url.isValid() or url.scheme().lower() != 'ftp': self.ftp.connectToHost(self.root, 21) self.ftp.login() self.setCursor(QtCore.Qt.WaitCursor) self.fileList.clear() self.currentPath = '/'.join(self.path.split('/')[:-1]) self.ftp.cd(self.path) self.cdToParentButton.setEnabled(True) else: self.ftp.connectToHost(url.host(), url.port(21)) user_name = url.userName() if user_name: try: # Python v3. user_name = bytes(user_name, encoding='utf-8') except: # Python v2. pass self.ftp.login(QtCore.QUrl.fromPercentEncoding(user_name), url.password()) else: self.ftp.login() if url.path(): self.ftp.cd(url.path()) self.fileList.setEnabled(True)
def change_path(self, path): """ .. py:attribute:: change_path() :param path: :type path: :rtype: UNKNOWN .. note:: .. todo:: """ self.ftp = QtNetwork.QFtp(self) self.setCursor(QtCore.Qt.WaitCursor) self.fileList.clear() self.isDirectory.clear() self.ftp.cd(path) self.ftp.list()
def __init__(self, url, parent): super(FtpReply, self).__init__(parent) self.items = [] self.content = QtCore.QByteArray() self.ftp = QtNetwork.QFtp(self) self.ftp.listInfo.connect(self.processListInfo) self.ftp.readyRead.connect(self.processData) self.ftp.commandFinished.connect(self.processCommand) self.offset = 0 self.units = ["bytes", "K", "M", "G", "Ti", "Pi", "Ei", "Zi", "Yi"] self.setUrl(url) self.ftp.connectToHost(url.host())
def __init__(self, client, *args, **kwargs): BaseClass.__init__(self, *args, **kwargs) self.setupUi(self) self.client = client self.currentMod = None self.modFiles = None self.versionFiles = None self.login = None self.password = None self.fileToUpload = None self.currentUid = None self.ftp = QtNetwork.QFtp(self) self.ftp.commandFinished.connect(self.ftpCommandFinished) self.ftp.listInfo.connect(self.addToList) self.ftp.dataTransferProgress.connect(self.updateDataTransferProgress) self.ftplist = [] self.progressDialog = QtGui.QProgressDialog(self) self.progressDialog.canceled.connect(self.cancelUpload) self.client.featuredModManager.connect(self.manageMod) self.client.featuredModManagerInfo.connect(self.manageModInfo) self.filesTable.cellPressed.connect(self.fileClicked) self.versionTable.cellPressed.connect(self.versionClicked) self.filesTable.horizontalHeader().setStretchLastSection ( True ) self.versionTable.horizontalHeader().setStretchLastSection ( True ) self.setStyleSheet(self.client.styleSheet())