Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Kindly help me with the below error

"the remote server returned an error 550 file unavailable e.g. file not found no access ."

I am trying to upload file through FTPS.
It is not required for the FTPS server to have the file which I am going to upload.
Everytime I will upload new new files.
100s of files we will need to upload dail.

however I am getting the above error at uploadRequest.GetRequestStream().

Thanks in advance..

My code is below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
namespace ConsoleApplication1
{
    class Class1
    {
        public static void Main(string[] args)
        {
            Stream requestStream = null;
            FileStream fileStream = null;
            FtpWebResponse uploadResponse = null;
            try
            {
                Uri uploadUrl = new Uri("ftp://blaabll.blabala.com/folder/");
                string fileName = "c:\\sangeetha.xlsx";
                FtpWebRequest uploadRequest =
                 (FtpWebRequest)WebRequest.Create(uploadUrl + @"/" + fileName);
                uploadRequest.Method = WebRequestMethods.Ftp.UploadFile              //Since the FTP you are downloading to is secure, send
                //in user name and password to be able upload the file
                ICredentials credentials = new NetworkCredential(user, password);
                uploadRequest.Credentials = credentials;
                //UploadFile is not supported through an Http proxy
                //so we disable the proxy for this request.
                uploadRequest.Proxy = null;
                //uploadRequest.UsePassive = false; <--found from another forum and did not make a difference
           <b>      requestStream = uploadRequest.GetRequestStream()</b> 
                fileStream = File.Open(fileName, FileMode.Open);
                byte[] buffer = new byte[1024];
                int bytesRead;
                while (true)
                {
                    bytesRead = fileStream.Read(buffer, 0, buffer.Length);
                    if (bytesRead == 0)
                        break;
                    requestStream.Write(buffer, 0, bytesRead);
                }
                //The request stream must be closed before getting
                //the response.
                requestStream.Close();
                uploadResponse =
                  (FtpWebResponse)uploadRequest.GetResponse();
            }
            catch (UriFormatException ex)
            {
             //   ErrorsHappened.Items.Add("Error: " + ex.Message);
            }
            catch (IOException ex)
            {
              // ErrorsHappened.Items.Add("Error: " + ex.Message);
            }
            catch (WebException ex)
            {
                //ErrorsHappened.Items.Add("Error: " + ex.Message);
            }
            finally
            {
                if (uploadResponse != null)
                    uploadResponse.Close();
                if (fileStream != null)
                    fileStream.Close();
                if (requestStream != null)
                    requestStream.Close();
            }
        }
    }
}
Posted
Updated 19-Apr-11 3:14am
v2
Comments
Toniyo Jackson 19-Apr-11 9:14am    
Added pre tag

1 solution

Error 550 is a permission failure (source[^], thanks Google). So, chances are you did not set up the permissions on the folder you are trying to write to correctly for the user you're using. Make sure that either that user owns the folder and it has access flags at least 5xx, or the user is in the same group as the folder owner and it has access flags at least x5x. Use chmod to change the access flags. (You could also do it with global write permission, xx5, but unless it's an anonymous drop that is not recommended as anyone could write there.)
 
Share this answer
 
v2

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



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