Click here to Skip to main content
13,053,845 members (60,551 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I was trying to upload file using ftp.(To a Linux machine). The following is the code, which I have tried.
            string filename = @"C:\Users\Admin\AppData\Local\Temp\Roaming.Doc";
            String ftpServerIP = "";
            FileInfo fileInf = new FileInfo(filename);
            FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(ftpServerIP + "/" + fileInf.Name);
            request.Method = WebRequestMethods.Ftp.UploadFile;
            request.Credentials = new NetworkCredential("abc", "123$");
            request.UsePassive = true;
            request.UseBinary = true;
            request.KeepAlive = false;
            //Load the file
            FileStream stream = File.OpenRead(filename);
            byte[] buffer = new byte[stream.Length];
            stream.Read(buffer, 0, buffer.Length);
            Stream reqStream = request.GetRequestStream();
            reqStream.Write(buffer, 0, buffer.Length);
        catch (Exception ex)

The same is working in a windows PC, but fails in a Linux PC with the following exception.

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

Can anyone please help me to solve this?

Posted 26-Jul-12 1:39am
Zoltán Zörgő 26-Jul-12 7:58am
Have you checked with a standalone ftp client that the path is correct?
Sebastian T Xavier 26-Jul-12 8:11am
Yes, I have verified it...
Zoltán Zörgő 26-Jul-12 12:37pm
Than use that client and a sniffer like Microsoft Network Monitor to see what happens behind the scenes. Or use a more standard ftp client approach, like this:
Suvabrata Roy 26-Jul-12 11:32am
In FTP it dose not matter which OS you are using what dose matter that's which protocol u r using ( FTP, SFTP,FTPS) if this Code work in Windows pc then it should work in Linux.
But i think is dose not able to recognized the file in Linux system.
Path Details:

Or try File Zillla (
Richard MacCutchan 26-Jul-12 11:51am
The filename you are using is not valid in Linux, it's a Windows path.
Zoltán Zörgő 26-Jul-12 12:35pm
This was also my first tough, but FileInfo.Name contains only the file name, "Roaming.Doc" in this case, which is valid in linux.
Sebastian T Xavier 26-Jul-12 12:41pm
I think the issue is with permissions. When I set ftp path to pub , this code worked and I was able to upload this file.
Richard MacCutchan 26-Jul-12 12:51pm
That certainly makes sense.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi Sebastian,
I had the same issue. Hope the following link may help you or someone to overcome the problem.

Click here

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 12 Aug 2015
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100