2

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");
Porphan
  • 153
  • 4
  • 11

2 Answers2

3

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.

Bobson
  • 13,498
  • 5
  • 55
  • 80
  • You are right I must choose the file name on the server too but don't you think if it is going to be like that firstly we need to create a file with that name on the server? like what we do in windows. first we create a file: 'File.Create()'. – Porphan Jun 13 '13 at 04:26
  • @Porphan - No, `UploadFile` handles that for you. In fact, it's quite possible that if you create the file, *then* upload it, you'll get an error preventing you from overwriting the file (depending on permissions and such). – Bobson Jun 13 '13 at 13:07
0

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

Community
  • 1
  • 1