python - ftplib.error_pern 501 No File Name? -
name = raw_input() ftp = ftp("") ftp.login('','') #these work fine ftp.storbinary("stor", "%s.txt" % (name)) # think issue here ftp.quit()
the programme crashes reaches part, googled , unable find answer, have tried typing name of file, same result.
what doing wrong?
if take @ docs, storbinary
method takes form of ('stor filename', <file_object>)
. issue above don't have finish stor
command first (command
) argument. since need pass open file handler file
argument, seek like:
ftp.storbinary("stor %s.txt" % (name), open("%s.txt" % name, 'rb'))
which create open file handler based on name raw_input
(as you're accepting input, you'd want wary of malicious input well). assuming handle that, context manager used open file (and ensure closes):
my_file = "%s.txt" % name open(my_file, "rb") f: ftp.storbinary("stor %s" % (my_file), f)
python ftplib
No comments:
Post a Comment