Click here to Skip to main content
11,715,043 members (63,540 online)
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.

1 solution

Rate this: bad
good
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
  Permalink  
v2

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 530
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 115
0 Sergey Alexandrovich Kryukov 775
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 12 Aug 2015
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