5

I'm trying to upload a file using ftplib in Python.

ftp = FTP('...')
ftp.login('user', 'pass')                   
f = open(filename)
ftp.storbinary(filename, f)
f.close()
ftp.quit()

storbinary is returning error_perm: 500 Unknown command., which is strange since I'm following its specification. Google search returns very little information. Anyone encountered this problem ?

FranGoitia
  • 1,965
  • 3
  • 30
  • 49

1 Answers1

8

It looks like you're using storbinary incorrectly. You want to pass "STOR filename-at-location", f) to send the file. Does this work?

ftp = FTP('...')
ftp.login('user', 'pass')
with open(filename) as contents:
    ftp.storbinary('STOR %s' % filename, contents)
ftp.quit()
Tom
  • 22,301
  • 5
  • 63
  • 96
  • filename is the name of the file a I want to upload which is at the current location – FranGoitia Oct 14 '15 at 17:18
  • 1
    Ok, but if the filename doesn't have any slashes in it, that means you're trying to upload to the root directory you are logging into. Is that your intent? – Tom Oct 14 '15 at 17:19