Python FTP上传栏

标签 python file-upload ftp

我正在 python 中使用 FTPLib 上传文件,并且有一个带有 progressbar 2.2. 的 cli 加载栏 我需要制作一个加载栏来告诉上传进度。

有人有关于该主题的任何信息吗?

谢谢,乔达梅里奥


正如Senthil Kumaran指出的,ftplib.storbinary函数中有一个回调参数,但我不知道如何使用它。

我试过这个。我希望它在每次上传一个字节时打印该消息。

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()

最佳答案

对代码进行小更改:

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()

回调需要稍后调用。如果您在将其作为参数传递时调用它,则会传递它的返回值。由于您的callback函数没有返回值,因此它将传入None

关于Python FTP上传栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5673170/

相关文章:

c# - 为什么 FtpWebRequest 会为此现有目录返回一个空流?

Python 切片字符串或添加到列表列表中的字符串

Python Pandas 按多列计数透视分组

python - 列表字典的笛卡尔积作为项目

javascript - Chrome 不支持 TypedArray.prototype.slice()

ruby-on-rails - 在 Rails 中将图像存储为模型

java - 如何在 servlet 3.0 中获取文件类型

java - FTP 确认传输完成

java - Spring FTP 入站 channel 适配器每隔一定时间将日志记录到 FTP

python - 在 __init__ 中应用属性 setter 逻辑