Hello, I am trying to upload a PDF using Python to an outside FTP server. However, I keep getting the error about concatenating string and and file objects.
CODE:
import ftplib
# Logging into ftp site with login information
session = ftplib.FTP("host","username","password")
print('Logging in')
# Choosing file to send
filename = "TEST12142020.pdf"
filepath = open(r'G:\\GIS\\filepath\\TEST12142020.pdf', 'rb')
print ('Opened file')
# Sending the file
print('Sending file')
session.storbinary('STOR ' + filepath, filename)
print('Sent file')
# Closing file and ftp
file.close()
print('Closing file')
session.quit()
ERROR:
Logging in
Opened file
Sending file
Traceback (most recent call last):
File "G:\pathname\UploadtoFTPTest.py", line 14, in <module>
session.storbinary('STOR ' + filepath, filename)
TypeError: cannot concatenate 'str' and 'file' objects
Solved! Go to Solution.
The error is pretty clear: Can't change directory to /srv/ftp/pub/crimemaps: No such file or directory
Can you verify that path is correct and the folders exist in the ftp site?
Oops, I had forgotten a folder name in the path. Thank you so much for all your help!!