Search This Blog

Thursday, November 19, 2015

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

I had a need to develop a small C# app to dynamically configure static webpages from a database (simple tables of phone numbers) and then push them to a webserver using FTP.

Using the new .NET 4.5 FTP tools in "System.Net" I coded the app (example in https://msdn.microsoft.com/en-us/library/ms229715%28v=vs.110%29.aspx) and I immediately ran into a problem pushing a file to a directory on the webserver where I knew I had rights. 

The error message was "Can't connect to FTP: (553) File name not allowed" on the line which creates the file on the remote server:           

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(@"ftp://servername.albany.edu/www/prod/biology/phone_numbers/test1.html");

My mistake was forgetting that my target was a UNIX server and not a Microsoft IIS server -- after a UNIX servername you need a double-slash to indicate the server's root directory -- in my case, I needed to change it to:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(@"ftp://servername.albany.edu//www/prod/biology/phone_numbers/test1.html");