ftplib

Retrieve data from gz file on FTP server without writing it locally

随声附和 提交于 2019-12-03 22:48:30
I would like to retrieve the data inside a compressed gz file stored on an FTP server, without writing the file to the local archive. At the moment I have done from ftplib import FTP import gzip ftp = FTP('ftp.server.com') ftp.login() ftp.cwd('/a/folder/') fileName = 'aFile.gz' localfile = open(fileName,'wb') ftp.retrbinary('RETR '+fileName, localfile.write, 1024) f = gzip.open(localfile,'rb') data = f.read() This, however, writes the file "localfile" on the current storage. I tried to change this in from ftplib import FTP import zlib ftp = FTP('ftp.server.com') ftp.login() ftp.cwd('/a/folder/

Python: Open a Listening Port Behind a Router (upnp?)

对着背影说爱祢 提交于 2019-12-03 18:57:17
问题 I've developed an application that is essentially just a little ftp server with the ability to specify which directory you wish to share on startup. I'm using ftplib for the server because it's sick easy. The only issue I'm having is that if you are behind a router you have to manually forward the ports on your router and I'm finding that it's a little too complicated for my users (aka co-workers/clients). So I've been looking for a simple solution to open ports but I'm finding that most APIs

How do I parse a listing of files to get just the filenames in Python?

让人想犯罪 __ 提交于 2019-12-03 08:41:41
So lets say I'm using Python's ftplib to retrieve a list of log files from an FTP server. How would I parse that list of files to get just the file names (the last column) inside a list? See the link above for example output. Using retrlines() probably isn't the best idea there, since it just prints to the console and so you'd have to do tricky things to even get at that output. A likely better bet would be to use the nlst() method, which returns exactly what you want: a list of the file names. e-satis This best answer You may want to use ftp.nlst() instead of ftp.retrlines() . It will give

Checking a Python FTP connection

血红的双手。 提交于 2019-12-03 07:45:39
I have a FTP connection from which I am downloading many files and processing them in between. I'd like to be able to check that my FTP connection hasn't timed out in between. So the code looks something like: conn = FTP(host='blah') conn.connect() for item in list_of_items: myfile = open('filename', 'w') conn.retrbinary('stuff", myfile) ### do some parsing ### How can I check my FTP connection in case it timed out during the ### do some parsing ### line? Sean Dawson Send a NOOP command. This does nothing but check that the connection is still going and if you do it periodically it can keep

sftp using ftplib

核能气质少年 提交于 2019-12-01 15:33:42
I need to download a file from a host using sFTP. Do you know if is it possible to do that using python ftplib? I saw an example here , but when I try to connect I receive EOFError . I tried this code: import ftplib ftp = ftplib.FTP() ftp.connect( "1.2.3.4", "22" ) This method returns with an error after long time so I cannot perform a call to login. I cannot try the constructor FTP([host[, user[, passwd[, acct[, timeout]]]]]) because my port is 22 but ftplib default is 21. If I follow the example ftp = ftplib.FTP("1.2.3.4") ftp = ftplib.FTP("1.2.3.4","22") I receive a connection refused so I

sftp using ftplib

こ雲淡風輕ζ 提交于 2019-12-01 15:22:11
问题 I need to download a file from a host using sFTP. Do you know if is it possible to do that using python ftplib? I saw an example here, but when I try to connect I receive EOFError . I tried this code: import ftplib ftp = ftplib.FTP() ftp.connect( "1.2.3.4", "22" ) This method returns with an error after long time so I cannot perform a call to login. I cannot try the constructor FTP([host[, user[, passwd[, acct[, timeout]]]]]) because my port is 22 but ftplib default is 21. If I follow the

Get folder size using FtpLib

只谈情不闲聊 提交于 2019-12-01 09:41:20
I'm using FtpLib (Python) to download a folder with files from an ftp server. But I want to know the size of the folder before I start downloading it. In the documentation I found FTP.size(filename) but that's just for files and not for folders... I could loop through all the files in the folder but it is possible that the folder contains subfolders. So does anyone know how to get the size of the folder using FtpLib? After some trial and error I found the solution. It's based on Alex Thorntons solution but I kept in mind that there could be subfolders. When it's a folder, the ftp.cwd() command

Python, add data to file on server how?

橙三吉。 提交于 2019-12-01 08:11:59
I'm appending values to a log file every 6th second. Every 30 sec I'm transferring this log to a server as a file. But instead of transfering the whole file, I just want to append the collected data to the file on my server. I haven't been able to figure out how to open the server file and then append the values. My code so far: session = ftplib.FTP(authData[0],authData[1],authData[2]) session.cwd("//"+serverCatalog()+"//") # open server catalog file = open(fileName(),'rb') with open(fileName(), 'rb') as f: f = f.readlines() for line in f: collected = line # In some way open server file, write

Update PyQt progress from another thread running FTP download

一曲冷凌霜 提交于 2019-12-01 07:51:29
问题 I want to access progress bar's (which is in the Ui_MainWindow() class) setMaximum() from another class/thread ( DownloadThread() class). I tried making DownloadThread() class inherit from Ui_MainWindow : DownloadThread(Ui_MainWindow) . But when I try to set the maximum progress bar value: Ui_MainWindow.progressBar.setMaximum(100) I get this error: AttributeError: type object 'Ui_MainWindow' has no attribute 'progressBar' My code: class Ui_MainWindow(object): def setupUi(self, MainWindow): #

Python, add data to file on server how?

南楼画角 提交于 2019-12-01 06:32:26
问题 I'm appending values to a log file every 6th second. Every 30 sec I'm transferring this log to a server as a file. But instead of transfering the whole file, I just want to append the collected data to the file on my server. I haven't been able to figure out how to open the server file and then append the values. My code so far: session = ftplib.FTP(authData[0],authData[1],authData[2]) session.cwd("//"+serverCatalog()+"//") # open server catalog file = open(fileName(),'rb') with open(fileName