问题描述
全部问候,
我正在尝试通过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
推荐答案
这篇关于在winforms app c#中使用ftp filezilla上传文件和目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!