Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi
I was trying to upload file using ftp.(To a Linux machine). The following is the code, which I have tried.
C#
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
Updated 27-Jan-21 22:55pm
Comments
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: http://www.codeproject.com/Articles/11991/An-FTP-client-library-for-NET-2-0
Suvabrata Roy 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 26-Jul-12 11:51am    
The filename you are using is not valid in Linux, it's a Windows path.

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

Click here
 
Share this answer
 
v2
Check disk space on the remote server first.
I had the same issue and found out it was because the remote server i was attempting to upload files to had run out of disk space on the partition or filessytem.
 
Share this answer
 
v2

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900