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

I need to FTP a file to a directory. In .Net I have to use a file on the destination folder to create a connection so I manually put Blank.dat on the server using FTP. I checked the access (ls -l) and it is -rw-r--r--. But when I attempt to connect to the FTP folder I get: "The remote server returned an error: (553) File name not allowed" back from the server. The research I have done says that this may arrise from a permissions issue but as I have said I have permissions to view the file and can run ls from the folder. What other reasons could cause this issue and is there a way to connect to the folder without having to specify a file?

            byte[] buffer;
            Stream reqStream;
            FileStream stream;
            FtpWebResponse response;
            FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(string.Format("ftp://{0}/{1}", SRV, DIR)));
            request.Method = WebRequestMethods.Ftp.UploadFile;
            request.Credentials = new NetworkCredential(UID, PASS);
            request.UseBinary = true;
            request.Timeout = 60000 * 2;
            for (int fl = 0; fl < files.Length; fl++)
                request.KeepAlive = (files.Length != fl);
                stream = File.OpenRead(Path.Combine(dir, files[fl]));
                reqStream = request.GetRequestStream();
                buffer = new byte[4096 * 2];
                int nRead = 0;
                while ((nRead = stream.Read(buffer, 0, buffer.Length)) != 0)
                    reqStream.Write(buffer, 0, nRead);

                response = (FtpWebResponse)request.GetResponse();


Although replying to an old post just thought it might help someone.

When you create your ftp url make sure you are not including the default directory for that login.

for example this was the path which I was specifying and i was getting the exception 553 FileName not allowed exception


The login which i used had the default directory gold/ the supplied url became invalid as it was trying to locate the whole path in the default directory.I amended my url string accordingly and was able to get rid of the exception.

my amended url looked like




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:

You must be careful with names and paths:

 string FTP_Server = @"";
 string myFile="text1.txt";
 string myDir=@"D:/Texts/Temp/";

if you are sending to a file caled text1.txt located at d:/texts/temp


    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(FTP_Server+myFile);
    request.Method = WebRequestMethods.Ftp.UploadFile;                      

    request.Credentials = new NetworkCredential(FTP_User, FTP_Password);    

    StreamReader sourceStream = new StreamReader(TempDir+myFile);                  
    byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());

    Stream requestStream = request.GetRequestStream();
    requestStream.Write(fileContents, 0, fileContents.Length);              

notice that at one moment you use as destination

which contains not only directory but the new file name at FTP server as well (which in general can be different than the name of file on you hard drive)

and at other place you use as source


your directory has access limit. delete your directory and then create again with this code:

//create folder  
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("");
request.Method = WebRequestMethods.Ftp.MakeDirectory;
request.Credentials = new NetworkCredential(username, password);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true ;
using (var resp = (FtpWebResponse)request.GetResponse())


I saw something similar to this a while back, it turned out to be the fact that I was trying to connect to an internal iis ftp server that was secured using Active Directory.

In my network credentials I was using new NetworkCredential(@"domain\user", "password"); and that was failing. Switching to new NetworkCredential("user", "password", "domain"); worked for me.

I hope this will be helpful for someone

if you are using LINUX server, replace your request path from

FtpWebRequest req= (FtpWebRequest)WebRequest.Create(@"" + filename);


FtpWebRequest req= (FtpWebRequest)WebRequest.Create(@"" + filename);

the folder path is how you see in the server(ex: cpanel)

Although it's an older post I thought it would be good to share my experience. I came faced the same problem however I solved it myself. The main 2 reasons of this problem is Error in path (if your permissions are correct) happens when your ftp path is wrong. Without seeing your path it is impossible to say what's wrong but one must remember the things a. Unlike browser FTP doesn't accept some special characters like ~ b. If you have several user accounts under same IP, do not include username or the word "home" in path c. Don't forget to include "public_html" in the path (normally you need to access the contents of public_html only) otherwise you may end up in a bottomless pit

Another reason for this error could be that the FTP server is case sensitive. That took me good while to figure out.

I had this problem when I tried to write to the FTP site's root directory pro grammatically. When I repeated the operation manually, the FTP automatically rerouted me to a sub-directory and completed the write operation. I then changed my code to prefix the target filename with the sub-directory and the operation was successful.

Need Your Help

Can't reference system.drawing.dll

c# system.drawing imageresizer

i'm trying to resize images with ImageResizer, but keep getting a compilation error

Android - Set max length of logcat messages

android logging

By default, it seems that logcat will truncate any log message that it considers to be "too long". This happens both inside of Eclipse and when running logcat on the command line using adb -d logc...