在winforms app c#中使用ftp filezilla上传文件和目录 [英] Upload file and directory with ftp filezilla in winforms app c#

查看:80
本文介绍了在winforms app c#中使用ftp filezilla上传文件和目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部问候,

我正在尝试通过ftp和filezilla使用c#,winforms应用程序将目录和文件从我的计算机上传到服务器。

这是我的代码,我有一个错误,我无法解决它:

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());
         sourceStream.Close();
         request.ContentLength = fileContents.Length;

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

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

         // Close the connection
         response.Close();
     }
 }





错误是:

Stream requestStream = request.GetRequestStream();

Le serveur遥远的retournéuneerreur:(550)Fichier不可取消(例如,例如,fichier introuvable,accès不可能)。



请帮忙!

先谢谢



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


推荐答案

你需要查看一下您的URL被设置为 - 它看起来不像您在服务器名称,目录和文件名之间放置路径分隔符(例如/)?



错误消息是找不到文件或拒绝访问。
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".


这篇关于在winforms app c#中使用ftp filezilla上传文件和目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆