Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

ftp

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);
                }
                stream.Close();
                reqStream.Close();

                response = (FtpWebResponse)request.GetResponse();
                response.Close();
            }
like image 517
NomadicDeveloper Avatar asked Feb 23 '12 17:02

NomadicDeveloper


2 Answers

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

ftp://myftpip/gold/central_p2/inbound/article_list/jobs/abc.txt

The login which i used had the default directory gold/central_p2.so 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

ftp://myftpip/inbound/article_list/jobs/abc.txt

Thanks,

Sab

like image 125
user1131926 Avatar answered Sep 19 '22 15:09

user1131926


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
like image 26
Darth Jurassic Avatar answered Sep 18 '22 15:09

Darth Jurassic