bonjour

je viens de developper un client avec c#.net pour l'Upload d'un fichier sur un serveur FTP
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        FileStream stream;
 
 
 
        public Form1()
        {
            InitializeComponent();
 
 
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
 
            connex();
        }
 
        private void connex()
        {
 
           /* FileStream stream = File.OpenRead(filePath.Text);
            byte[] buffer = new byte[stream.Length];
 
            FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTPAddress.Text);
 
            stream.Read(buffer, 0, buffer.Length);
            stream.Close();
            request.Method = WebRequestMethods.Ftp.UploadFile;
            request.Credentials = new NetworkCredential(username.Text, password.Text);
            request.UsePassive = true;
            request.UseBinary = true;
            request.KeepAlive = false;
            */
            FileInfo fileInf = new FileInfo(filePath.Text);
  string uri =FTPAddress.Text+"/"+filePath;
  FtpWebRequest reqFTP;
 
  // Create FtpWebRequest object from the Uri provided
 
  reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
 
  // Provide the WebPermission Credintials
 
  reqFTP.Credentials = new NetworkCredential(username.Text, password.Text);
 
  // By default KeepAlive is true, where the control connection is 
 
  // not closed after a command is executed.
 
  reqFTP.KeepAlive = false;
 
  // Specify the command to be executed.
 
  reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
 
  // Specify the data transfer type.
 
  reqFTP.UseBinary = true;
 
  // Notify the server about the size of the uploaded file
 
  reqFTP.ContentLength = fileInf.Length;
 
  // The buffer size is set to 2kb
 
  int buffLength = 2048;
  byte[] buff = new byte[buffLength];
  int contentLen;
 
  // Opens a file stream (System.IO.FileStream) to read 
 
  FileStream fs = fileInf.OpenRead();
 
  try
  {
        // Stream to which the file to be upload is written
 
        Stream strm = reqFTP.GetRequestStream();
 
        // Read from the file stream 2kb at a time
 
        contentLen = fs.Read(buff, 0, buffLength);
 
        // Till Stream content ends
 
        while (contentLen != 0)
        {
            // Write Content from the file stream to the 
 
            // FTP Upload Stream
 
            strm.Write(buff, 0, contentLen);
            contentLen = fs.Read(buff, 0, buffLength);
        }
 
        // Close the file stream and the Request Stream
 
        strm.Close();
        fs.Close();
  }
  catch(Exception ex)
    {
        MessageBox.Show(ex.Message, "Upload Error");
    }
 
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog browseFile = new OpenFileDialog();
 
            browseFile.Filter = "TXT Files (*.env)|*.env";
 
            browseFile.Title = "Browse XML file";
 
            if (browseFile.ShowDialog() == DialogResult.Cancel)
 
                return;
 
            try
            {
 
                filePath.Text = browseFile.FileName;
 
            }
 
            catch (Exception)
            {
 
                MessageBox.Show("Error opening file", "File Error",
 
                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
 
            }
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
        }
 
        private void filePath_TextChanged(object sender, EventArgs e)
        {
 
        }
    }
}
Ce code me permet de me connecter au serveur cependant il me presente une erreur suivante lorsque j'essaie de deposer le fichier :

erreur(550) Fichier non disponible (par exemple fichier introuvable,accés impossible)
Merci