Python FTP上传栏 [英] Python FTP uploading bar
问题描述
我使用python上传FTPLib文件,并使用
我需要做一个加载栏来告诉上传进度。
有没有人有任何关于这个主题的信息?
谢谢,giodamelio
正如Senthil Kumaran指出的那样,参数在ftplib.storbinary函数,但我不知道如何使用它。
我试过这个。每次上传一个字节,我都希望它能打印出消息。
import ftplib
$ b $ def callback ():
print(这是回调函数)
s = ftplib.FTP('myserver.com','login','password')#连接
f = open('test.txt','rb')#发送
的文件s.storbinary('STOR test.txt',f,1024,callback())#发送文件
f.close()#关闭文件和FTP
s.quit()
$ p $
import ftplib
def callback(p):
print(这是回调函数)
$ bs = ftplib.FTP('myserver.com','login','password' )#连接
f = open('test.txt','rb')#文件发送
s.storbinary('STOR test.txt',f,1024,callback)#发送文件
f.close() #关闭文件和FTP
s.quit()
回调需要稍后调用上。如果在您将其作为参数传递时调用它,则会传递返回值。由于你的回调
函数没有返回,它会传入 None
。
I am uploading a file with FTPLib in python and have a cli loadingbar with progressbar 2.2. I need to make a loading bar to tell the progress of the upload.
Does anyone have any info on the topic?
Thanks, giodamelio
As Senthil Kumaran pointed out, there is a callback parameter in the ftplib.storbinary function but I do not know how to use it.
I tried this. I expected it to print the message every time a byte was uploaded.
import ftplib
def callback():
print("This is the callback function")
s = ftplib.FTP('myserver.com','login','password') # Connect
f = open('test.txt','rb') # file to send
s.storbinary('STOR test.txt', f, 1024, callback()) # Send the file
f.close() # Close file and FTP
s.quit()
Small change to your code:
import ftplib
def callback(p):
print("This is the callback function")
s = ftplib.FTP('myserver.com','login','password') # Connect
f = open('test.txt','rb') # file to send
s.storbinary('STOR test.txt', f, 1024, callback) # Send the file
f.close() # Close file and FTP
s.quit()
The callback needs to be called later on. If you invoke it as you pass it as a parameter, it's return value is passed instead. Since your callback
function has no return, it would pass in None
.
这篇关于Python FTP上传栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!