If you take a look at the docs, the storbinary
method takes the form of ('STOR filename', <file_object>)
. The issue above is that you don't have a complete STOR
command as your first (command
) argument. Since you need to pass an open file handler as the file
argument, you could try something like:
ftp.storbinary("STOR %s.txt" % (name), open("%s.txt" % name, 'rb'))
Which would create an open file handler based on the name from raw_input
(as you're accepting input, you'd want to be wary of malicious input as well). Assuming you handle that, a context manager could be used to open the file (and ensure it closes):
my_file = "%s.txt" % name
with open(my_file, "rb") as f:
ftp.storbinary("STOR %s" % (my_file), f)