2052:b89c21c96127 | 2053:ef81185e8b89 |
---|---|
100 | 100 |
101 class FtpReply(QNetworkReply): | 101 class FtpReply(QNetworkReply): |
102 """ | 102 """ |
103 Class implementing a network reply for FTP resources. | 103 Class implementing a network reply for FTP resources. |
104 """ | 104 """ |
105 Monthnames2Int = { | |
106 "Jan": 1, | |
107 "Feb": 2, | |
108 "Mar": 3, | |
109 "Apr": 4, | |
110 "May": 5, | |
111 "Jun": 6, | |
112 "Jul": 7, | |
113 "Aug": 8, | |
114 "Sep": 9, | |
115 "Oct": 10, | |
116 "Nov": 11, | |
117 "Dec": 12, | |
118 } | |
119 | |
120 def __init__(self, url, accessHandler, parent=None): | 105 def __init__(self, url, accessHandler, parent=None): |
121 """ | 106 """ |
122 Constructor | 107 Constructor |
123 | 108 |
124 @param url requested FTP URL (QUrl) | 109 @param url requested FTP URL (QUrl) |
134 | 119 |
135 self.__items = [] | 120 self.__items = [] |
136 self.__content = QByteArray() | 121 self.__content = QByteArray() |
137 self.__units = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] | 122 self.__units = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] |
138 self.__dirLineParser = FtpDirLineParser() | 123 self.__dirLineParser = FtpDirLineParser() |
124 self.__fileBytesReceived = 0 | |
139 | 125 |
140 if url.path() == "": | 126 if url.path() == "": |
141 url.setPath("/") | 127 url.setPath("/") |
142 self.setUrl(url) | 128 self.setUrl(url) |
143 | 129 |
225 retry = False | 211 retry = False |
226 if ok: | 212 if ok: |
227 self.__ftp.retrlines("LIST " + self.url().path(), self.__dirCallback) | 213 self.__ftp.retrlines("LIST " + self.url().path(), self.__dirCallback) |
228 if len(self.__items) == 1 and \ | 214 if len(self.__items) == 1 and \ |
229 self.__items[0].isFile(): | 215 self.__items[0].isFile(): |
216 self.__fileBytesReceived = 0 | |
230 self.__setContent() | 217 self.__setContent() |
231 self.__ftp.retrbinary( | 218 self.__ftp.retrbinary( |
232 "RETR " + self.url().path(), self.__retrCallback) | 219 "RETR " + self.url().path(), self.__retrCallback) |
233 self.__content.append(512 * b' ') | 220 self.__content.append(512 * b' ') |
234 self.readyRead.emit() | 221 self.readyRead.emit() |
329 Private slot handling the reception of data. | 316 Private slot handling the reception of data. |
330 | 317 |
331 @param data data received from the FTP server (bytes) | 318 @param data data received from the FTP server (bytes) |
332 """ | 319 """ |
333 self.__content += QByteArray(data) | 320 self.__content += QByteArray(data) |
321 self.__fileBytesReceived += len(data) | |
322 self.downloadProgress.emit(self.__fileBytesReceived, self.__items[0].size()) | |
323 self.readyRead.emit() | |
334 | 324 |
335 QCoreApplication.processEvents() | 325 QCoreApplication.processEvents() |
336 | 326 |
337 def __setContent(self): | 327 def __setContent(self): |
338 """ | 328 """ |