Blocking sockobj.makefile('w') objects
Pedro Rodriguez
pedro_rodriguez at club-internet.fr
Tue Jan 15 08:51:53 EST 2002
"Stefan Schwarzer" <s.schwarzer at ndh.net> wrote:
> Hello all
>
> Please excuse the long posting.
>
> I'm writing a module to make FTP connections appear as file-like objects
> (I will upload the code to the Vaults when it's ready). Example code
> (code that is used behind the scenes follows below):
>
> import ftputil
> host = ftputil.FTPHost('ftp.domain.com', 'user', 'password') text =
> 'Some example text\nSecond line' fp = host.file('remote_name', 'w')
> fp.write(text)
> fp.close
> host.close()
>
> ...code snipped...
I "linearized" your example to narrow the problem :
import ftplib
host = ftplib.FTP('localhost', 'user', 'passwd')
command = 'TYPE A'
host.voidcmd(command)
command = 'STOR remote_name'
conn = host.transfercmd(command)
# host.voidresp() XXX this where it hangs !!!!!!
fp = conn.makefile('w')
fp.write("Hello World")
fp.close()
conn.close()
print host.voidresp()
The call to voidresp() is the one that hangs. When looking
at retr.../stor... functions in ftplib, the call to the
(undocumented and private (?)) voidresp is done at the end
(to flush the response of the server I presume).
And about the difference between sendcmd() and voidcmd(),
according to the code, it seems that the voidcmd will
raise an exception if the return code from the server
is not 2yz (excerpt of RFC959)
2yz Positive Completion reply
The requested action has been successfully completed. A
new request may be initiated.
So my understanding is that voidcmd should be used at the end
of command to check that everything was ok.
Hoping this helps,
Regards,
--
Pedro
More information about the Python-list
mailing list