Click here to Skip to main content
11,414,561 members (65,740 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Linux FTP

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 2:39am
Zoltán Zörgő at 26-Jul-12 7:58am
Have you checked with a standalone ftp client that the path is correct?
Sebastian T Xavier at 26-Jul-12 8:11am
Yes, I have verified it...
Zoltán Zörgő at 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 at 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 at 26-Jul-12 11:51am
The filename you are using is not valid in Linux, it's a Windows path.
Zoltán Zörgő at 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 at 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 at 26-Jul-12 12:51pm
That certainly makes sense.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,130
1 OriginalGriff 7,477
2 Maciej Los 3,710
3 Abhinav S 3,298
4 Peter Leow 3,084

Advertise | Privacy | Mobile
Web04 | 2.8.150427.4 | Last Updated 26 Jul 2012
Copyright © CodeProject, 1999-2015
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