-1

i have this code in python2.7 for upload photos.zip file on the server via ftp.

import ftplib
session = ftplib.FTP('server.address.com','USERNAME','PASSWORD')
file = open('c:\archived\photos.zip','rb')                  # file to send
session.storbinary('STOR photos.zip', file)                 # send the file
file.close()                                                # close file and FTP
session.quit()

but i have this error :

raceback (most recent call last):
File "a.py", line 24, in <module>
file = open('c:\archived\photos.zip','rb')
IOError: [Errno 22] invalid mode ('rb') or filename: 'c:\archived\photos.zip'

also I used this solution :

file = open(os.path.join('c:/','archived','photos.zip'),'rb')

but I get this error :

Traceback (most recent call last):
  File "s.py", line 28, in <module>
    session.storbinary('s.zip', file)
  File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 479, in storbinary
    conn = self.transfercmd(cmd, rest)
  File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 378, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 341, in ntransfercmd
    resp = self.sendcmd(cmd)
  File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 251, in sendcmd
    return self.getresp()
  File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 226, in getresp
    raise error_perm, resp
ftplib.error_perm: 500 Unknown command.
erikson
  • 1
  • 2
  • Try removing the file open mode completely which is `'rb'` in this case. – Underoos Jul 11 '19 at 11:50
  • 1
    second error shows that you forgot `STOR` in `session.storbinary('s.zip', file)` – furas Jul 11 '19 at 11:59
  • @furas is right - the error message you have posted does not come from the code you have posted. The code you have posted, would error already on the `open` call, due to in invalid string syntax (what you have asked already in your previous question). – Martin Prikryl Jul 11 '19 at 12:04
  • now what i must doing? – erikson Jul 11 '19 at 12:56
  • Use your [original code](https://stackoverflow.com/q/56955895/850848), just fix the [single line as I have already shown you](https://stackoverflow.com/a/56956042/850848). – Martin Prikryl Jul 11 '19 at 14:08

1 Answers1

0

Try using forward slashes :

file = open('c:/archived/photos.zip','rb')                  # file to send
Wura
  • 147
  • 1
  • 10