Chris Chris - 1 year ago 171
Python Question

Python FTP filename invalid error

I'm trying to upload a file using ftp in python, but I get an error saying:

ftplib.error_perm: 550 Filename invalid

when I run the following code:

ftp = FTP('', 'MY_FTP', '')
file = open('c:\Automation\FTP_Files\MaxErrors1.json', 'rb')
ftp.storbinary('STOR c:\Automation\FTP_Files\MaxErrors1.json', file)

I've checked that the file exists in the location I specified, does anyone know what might be causing the issue?

Answer Source

The problem is that on the server, the path c:\Automation\FTP_Files\MaxErrors1.json is not valid. Instead try just doing:

ftp.storbinary('STOR MaxErrors1.json', file)