Question

So I was trying to upload a 1kb text file to my ftp server but this error comes up:

The remote server returned an error: (553) File name not allowed.

so what's wrong with my code?

WebClient upload = new WebClient();
upload.Credentials = new NetworkCredential("******", "*********");
upload.UploadFile("ftp://xxx.com/public_html", "G:/adress.txt");
Was it helpful?

Solution

It's hard to tell, because it's a server error not a code error. However, as currently written, you're trying to upload the file called adress.txt to become a file named public_html. I suspect there's already a directory with that name, and the conflict is preventing the upload. Try

upload.UploadFile("ftp://xxx.com/public_html/adress.txt", "G:/adress.txt");

instead.

OTHER TIPS

This might not apply to you, but if it is a Linux FTP server:

This may help for Linux FTP server.

So, Linux FTP servers unlike IIS don't have common FTP root directory. Instead, when you log on to FTP server under some user's credentials, this user's root directory is used. So FTP directory hierarchy starts from /root/ for root user and from /home/username for others.

So, if you need to query a file not relative to user account home directory, but relative to file system root, add an extra / after server name. Resulting URL will look like:

ftp://servername.net//var/lalala

Instead of:

ftp://xxx.com/public_html

You would need a second slash after the server name in addition to the full file name:

ftp://xxx.com//public_html/adress.txt

I ran into this same issue and it fixed it for me.

Source: Can't connect to FTP: (553) File name not allowed

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top