ChrisG29
ChrisG29

Reputation: 1571

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('xxx.xxx.x.xxx', 'MY_FTP', '')
ftp.cwd("/incoming")
file = open('c:\Automation\FTP_Files\MaxErrors1.json', 'rb')
ftp.storbinary('STOR c:\Automation\FTP_Files\MaxErrors1.json', file)
ftp.close()

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

Upvotes: 1

Views: 2580

Answers (3)

Mikail Land
Mikail Land

Reputation: 279

you should upload file without absolute path in ftp server for example :

import ftplib
session = ftplib.FTP('server.address.com','USERNAME','PASSWORD')
file = open('kitten.jpg','rb')                  # file to send
session.storbinary('STOR kitten.jpg', file)     # send the file
file.close()                                    # close file and FTP
session.quit()

Upvotes: 0

Klaus Byskov Pedersen
Klaus Byskov Pedersen

Reputation: 121057

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)

Upvotes: 3

Daniel Roseman
Daniel Roseman

Reputation: 600041

The argument to STOR needs to be the destination file name, not the source path. You should just do ftp.storbinary('STOR MaxErrors1.json', file).

Upvotes: 0

Related Questions