FTP状态问题。 (再次) [英] FTP status problems. (Again)

查看:141
本文介绍了FTP状态问题。 (再次)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我之前发过关于试图找到FTP状态的b / b
uplaod,但是没有任何工作可做。经过一番搜索后我找到了b $ b http://groups.google.com/group/comp....917c906cdc04d4

但它似乎不起作用,因为它只是上传文件并且确实

不打印。到屏幕上。当我使用

来自该链接的代码时,我就是我的代码。

import ftplib

import os

class dot_FTP(ftplib.FTP):

def storbinary(self,cmd,fp,blocksize = 8192):

self.voidcmd(''TYPE I '')

conn = self.transfercmd(cmd)

而1:

buf = fp.read(blocksize)

如果不是buf:break

conn.send(buf)

sys.stdout.write(''。'')

sys.stdout.flush()

conn.close()

返回self.voidresp()

ftp = ftplib.FTP(" ; FTPADDRESS")

ftp.login(" user"," pass")

file =" / file"

ftp .storbinary(" STOR" + file,open(file," rb"),1024)

ftp.quit()

有谁知道为什么这是不工作?有什么其他的方式

找出发送chunc的时间或文件上传的字节数?

谢谢。

解决方案

在星期五,2005-09-16在19:27 -0700,Nainto写道:

你好,我之前发过关于尝试找到FTP
上架的状态,但无法正常工作。经过一番搜索后,我发现
http://groups.google.com/group/comp....917c906cdc04d4
但似乎没有工作,因为它只是上传文件,并且不打印。到屏幕上。当我使用来自该链接的代码时,我就是我的代码。
import ftplib
import os
class dot_FTP(ftplib.FTP):
def storbinary(self,cmd,fp,blocksize = 8192):
self.voidcmd(''TYPE I'')
conn = self.transfercmd(cmd)
而1:
buf = fp.read(blocksize)
如果不是buf:break
conn.send(buf)
sys.stdout.write(''。'')
sys .stdout.flush()
conn.close()
返回self.voidresp()

ftp = ftplib.FTP(" FTPADDRESS")
ftp。 login(" user"," pass")
file =" / file"
ftp.storbinary(" STOR" + file,open(file," rb"),1024 )
ftp.quit()
有谁知道为什么这不起作用?有没有其他方法可以找出发送chunc的时间或文件的上传时间?
谢谢。




.. ..我自己没有尝试过这个,但你应该能够将内置文件对象子类化为
并准备自己的read()方法。东西

喜欢


类ProgressFile(文件):


def读取(self,size = None):

打印''。'',


如果尺寸不是无:

返回file.read(自我,尺寸)

否则:

返回file.read()


可能需要一些调整..然后将文件存储为


ftp.storbinary(" STOR" + file,ProgressFile(file," rb"),1024)


试一试。 。


-m

blockquote>

星期六,2005-09-17 04:42 +0000,marduk写道:


...我自己也没试过,但你应该能够继承
内置文件对象并准备自己的read()方法。类似

类ProgressFile(文件):

def读取(self,size = None):
print''。'',

如果大小不是无:
返回file.read(自我,大小)
否则:
返回file.read()

可能需要一些调整..然后将文件存储为

ftp.storbinary(STOR+文件,ProgressFile(文件,rb),1024)
尝试一下..

-m




我纠正了一些错误并对我以前的帖子进行了一些修改:


类ProgressFile(文件):

def读取(self,size = None):

来自sys import stdout


如果大小不是无:

buff = file.read(自我,大小)

如果buff:

stdout .write(''。'')

else:

stdout.write(''\ n'')

return buff

else:

buff =''''

而True:

new_str = file.read(self,1024)

stdout.write(''。'')

if new_str:

buff = buff + new_str

else:

stdout.write(''\ n'')

break

返回buff

如果__name__ ==''__ main__'':

import sys

fname = sys .argv [1]

f = ProgressFile(fname)

f.read()


谢谢,我我试试看。这会打印一段时间吗?


Hello, I have posted before about trying to find the status of an FTP
uplaod but couldn''t get anything to work. After some more searching I
found
http://groups.google.com/group/comp....917c906cdc04d4
but it does not seem to work because it just uploads the file and does
not print a . onto the screen. HEre is the code I have when I''m using
the code from that link.
import ftplib
import os
class dot_FTP(ftplib.FTP):
def storbinary(self, cmd, fp, blocksize=8192):
self.voidcmd(''TYPE I'')
conn = self.transfercmd(cmd)
while 1:
buf = fp.read(blocksize)
if not buf: break
conn.send(buf)
sys.stdout.write(''.'')
sys.stdout.flush()
conn.close()
return self.voidresp()
ftp = ftplib.FTP("FTPADDRESS")
ftp.login("user","pass")
file = "/file"
ftp.storbinary("STOR " + file, open(file, "rb"), 1024)
ftp.quit()
Does anyone know why this is not working? IS there any other way to
find out when a chunc has been sent or the bytes uploaded of a file?
Thanks.

解决方案

On Fri, 2005-09-16 at 19:27 -0700, Nainto wrote:

Hello, I have posted before about trying to find the status of an FTP
uplaod but couldn''t get anything to work. After some more searching I
found
http://groups.google.com/group/comp....917c906cdc04d4
but it does not seem to work because it just uploads the file and does
not print a . onto the screen. HEre is the code I have when I''m using
the code from that link.
import ftplib
import os
class dot_FTP(ftplib.FTP):
def storbinary(self, cmd, fp, blocksize=8192):
self.voidcmd(''TYPE I'')
conn = self.transfercmd(cmd)
while 1:
buf = fp.read(blocksize)
if not buf: break
conn.send(buf)
sys.stdout.write(''.'')
sys.stdout.flush()
conn.close()
return self.voidresp()
ftp = ftplib.FTP("FTPADDRESS")
ftp.login("user","pass")
file = "/file"
ftp.storbinary("STOR " + file, open(file, "rb"), 1024)
ftp.quit()
Does anyone know why this is not working? IS there any other way to
find out when a chunc has been sent or the bytes uploaded of a file?
Thanks.



.... and I haven''t tried this myself, but you should be able to subclass
the builtin file object and prepare your own read() method. Something
like

class ProgressFile(file):

def read(self, size = None):
print ''.'',

if size is not None:
return file.read(self, size)
else:
return file.read()

May need some tweaking.. then store the file as

ftp.storbinary("STOR " + file, ProgressFile(file, "rb"), 1024)

Give it a try..

-m


On Sat, 2005-09-17 at 04:42 +0000, marduk wrote:


... and I haven''t tried this myself, but you should be able to subclass
the builtin file object and prepare your own read() method. Something
like

class ProgressFile(file):

def read(self, size = None):
print ''.'',

if size is not None:
return file.read(self, size)
else:
return file.read()

May need some tweaking.. then store the file as

ftp.storbinary("STOR " + file, ProgressFile(file, "rb"), 1024)

Give it a try..

-m



I corrected some errors and made some modifications to my previous post:

class ProgressFile(file):
def read(self, size = None):
from sys import stdout

if size is not None:
buff = file.read(self, size)
if buff:
stdout.write(''.'')
else:
stdout.write(''\n'')
return buff
else:
buff = ''''
while True:
new_str = file.read(self, 1024)
stdout.write(''.'')
if new_str:
buff = buff + new_str
else:
stdout.write(''\n'')
break
return buff
if __name__ == ''__main__'':
import sys

fname = sys.argv[1]
f = ProgressFile(fname)
f.read()


Thanks, I''ll give this a try. This will print a period right?


这篇关于FTP状态问题。 (再次)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆