Click here to Skip to main content
15,908,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greeting all ,
I'm trying to upload directories and files from my computer to a server via ftp and filezilla with c# , winforms application .
Here is my code , I have an error that I can't solve it :
////INST : liste des directories Sources
 string[] Dir_N1 = { dirBin, dirContent, dirCulture, dirImages, dirLayout, dirPages, dirUserControls, dirXmlconfig };

 ////LOOP : parcourir  les reprertoires niveau1
 foreach (string d in Dir_N1)

     DirectoryInfo dir = new DirectoryInfo(filePath + d);
     FileInfo[] files = dir.GetFiles();
     foreach (FileInfo file in files)
         string URI = "ftp://" + ServerName.InnerText + "//TestDeploy" + d + file.Name;
         FtpWebRequest request = (FtpWebRequest)WebRequest.Create(URI);
         request.Credentials = new NetworkCredential(UserName.InnerText, Password.InnerText);

         // Copy the entire contents of the file to the request stream.

         StreamReader sourceStream = new StreamReader(file.FullName);
         request.Method = WebRequestMethods.Ftp.MakeDirectory;
         request.Method = WebRequestMethods.Ftp.UploadFile;
         byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
         request.ContentLength = fileContents.Length;

         // Upload the file stream to the server.
         Stream requestStream = request.GetRequestStream();
         requestStream.Write(fileContents, 0, fileContents.Length);

         // Get the response from the FTP server.
         FtpWebResponse response = (FtpWebResponse)request.GetResponse();

         // Close the connection

The error is :
Stream requestStream = request.GetRequestStream();
Le serveur distant a retourné une erreur : (550) Fichier non disponible (par exemple, fichier introuvable, accès impossible).

Any Help please !
Thanks in advance

Updated 25-Nov-14 4:08am
DamithSL 25-Nov-14 10:06am    
what is the error/errors? which line/lines you get those errors?
amiach 25-Nov-14 10:08am    
Ah sorry , I edited the post now
Member 10506391 25-Nov-14 11:00am    
please submit your error message in English
Sergey Alexandrovich Kryukov 25-Nov-14 11:51am    
Forget Filezilla. How is that relevant?

1 solution

You need to check what your URL is being set to - it does not look like you are putting path seperators (e.g. / ) between the server name, directory and filename?

The error message is "File not found or access denied".
Share this answer
amiach 25-Nov-14 11:13am    
The separators are already put between the server name, directory and filename
Duncan Edwards Jones 25-Nov-14 11:21am    
and does the path exist on the server?

(If not and you intend "request.Method = WebRequestMethods.Ftp.MakeDirectory;" to do that, don't forget you have to issue the request with "FtpWebResponse response = (FtpWebResponse)request.GetResponse();" before you continue...)
amiach 25-Nov-14 11:26am    
Yes it exist

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