0

i have this code in python 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 : T

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'
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
erikson
  • 1
  • 2

2 Answers2

0

You have to escape the backslashes in the path:

file = open('c:\\archived\\photos.zip','rb')
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
0

Use os.path.join which is considered better.

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

If you want to stick to your string, use \\ instead of \.

DanielM
  • 3,598
  • 5
  • 37
  • 53