Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Linux FTP
Hi
 
I was trying to upload file using ftp.(To a Linux machine). The following is the code, which I have tried.
 
        try
        {
            string filename = @"C:\Users\Admin\AppData\Local\Temp\Roaming.Doc";
            String ftpServerIP = "ftp://192.168.1.246:21/";
            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.Close();
            
            Stream reqStream = request.GetRequestStream();
            reqStream.Write(buffer, 0, buffer.Length);
            reqStream.Close();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.ReadLine();
        }
 
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?
 
Thanks
Sebastian
Posted 26-Jul-12 1:39am
Comments
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: http://www.codeproject.com/Articles/11991/An-FTP-client-library-for-NET-2-0
Suvabrata Roy at 26-Jul-12 11:32am
   
Hi,
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: http://en.wikipedia.org/wiki/Path_(computing)
 
Or try File Zillla (http://filezilla-project.org/)
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)



Advertise | Privacy | Mobile
Web01 | 2.8.141022.2 | Last Updated 26 Jul 2012
Copyright © CodeProject, 1999-2014
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