I am developing a project in C # and at this point I have to select a row from a DataGridView that I created, create a text file with that data and send the file created to an ftp server. I already did a search, but I could not find anything that was useful to me. If you want some code or some screenshot of my project I can make it available. This is the DataGridView code:
SqlConnection myConnection = new SqlConnection(@"Data source = **** ; Database=**** ; User Id=****; Password=*****");
myConnection.Open();
SqlCommand objcmd = new SqlCommand("SELECT TransDocument, TransSerial, TransDocNumber, PartyName, PartyLocalityID, TotalAmount, ShipToPostalCode FROM dbo.UXMenu WHERE Estado = 0", myConnection);
objcmd.ExecuteNonQuery();
SqlDataAdapter adp = new SqlDataAdapter(objcmd);
DataTable dt = new DataTable();
adp.Fill(dt);
dataGridViewEnviarDados.DataSource = dt;
dataGridViewEnviarDados.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
UPDATE:
I'musingthiscode:
FtpWebRequestrequest=(FtpWebRequest)WebRequest.Create("ftp://123.321.123" + arquivo.Name);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("usuario", "password");
StreamReader sourceStream = new StreamReader(arquivo.FullName);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
MessageBox.Show("Arquivo " + arquivo.Name + " foi enviado com sucesso. " + response.StatusDescription);
response.Close();'
But I have this error: