C# Transfert FTP - Upload
Bonjour,
J'ai un souci que je n'arrive pas à résoudre malgrés quelques recherches et quelques essais de differents code. Je developpe un petit client ftp qui doit transferer plusieurs fichiers en l'occurrence CSV.
L'erreur que j'obtiens est l'erreur 530 NON CONNECTE.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
public void TransfertFTP()
{
Log = new List<string>();
for (int i = 0; i <= TailleListe - 1; i++)
{
try
{
Uri ServeurFtp = new Uri("ftp://ftp.cluster1.easy-hebergement.net/%2fTest");
FtpWebRequest ftpClient = (FtpWebRequest)WebRequest.Create(ServeurFtp);
ftpClient.Credentials = new System.Net.NetworkCredential("***********", "*******", "ftp://ftp.cluster1.easy-hebergement.net");
ftpClient.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
ftpClient.UseBinary = true;
ftpClient.KeepAlive = true;
System.IO.FileInfo fi = new System.IO.FileInfo(pathDesFichiers + ListeFichiersTrouves[i]);
ftpClient.ContentLength = fi.Length;
byte[] buffer = new byte[4097]; //Fichier max de 4Mo
int bytes = 0;
int total_bytes = (int)fi.Length;
System.IO.FileStream fs = fi.OpenRead();
System.IO.Stream rs = ftpClient.GetRequestStream();
while (total_bytes > 0)
{
bytes = fs.Read(buffer, 0, buffer.Length);
rs.Write(buffer, 0, bytes);
total_bytes = total_bytes - bytes;
}
//fs.Flush();
fs.Close();
rs.Close();
FtpWebResponse uploadResponse = (FtpWebResponse)ftpClient.GetResponse();
uploadResponse.Close();
Deplacerfichier(ListeFichiersTrouves[i]);
}
catch (Exception e)
{
Console.WriteLine("Erreur Transfert FTP"+e.ToString());
Log.Add("Echec Transfert FTP du fichier : " + ListeFichiersTrouves[i]);
}
}
} |