name = raw_input()
ftp = FTP("")
ftp.login('','') #These work fine
ftp.storbinary("STOR", "%s.txt" % (name)) # I think the issue is here
ftp.quit()
The program always crashes as it reaches this part, I googled and was unable to find an answer, I have even tried just typing the name of the file, but with the same result.
What am I doing wrong?
If you take a look at the docs, the
storbinarymethod takes the form of('STOR filename', <file_object>). The issue above is that you don’t have a completeSTORcommand as your first (command) argument. Since you need to pass an open file handler as thefileargument, you could try something like: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):