I have an executable that sends a .CSV file via FTP to my client.
Running on my local machine works perfectly but when running on my client's server it does not work.
Whenever it falls on the line
request.GetRequestStream()
I get the error message
Unable to connect to the remote server
Follow the code for my application
string pathArquivoConsumoFull = string.Format("{0}\{1}", arquivoData[0].DirectoryName, arquivoData[0].Name);
Console.WriteLine("patharquivoConsumo - " + pathArquivoConsumoFull);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(enderecoFTP + "/" + Path.GetFileName(arquivoData[0].Name));
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(nomeUsuarioFTP, passFTP);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
var stream = File.OpenRead(pathArquivoConsumoFull);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();
Console.WriteLine("Entra no reqStream");
using (var reqStream = request.GetRequestStream())
{
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
}
Console.WriteLine("Passou reqStream!!!");
I installed FileZila on the server and I have access to the FTP address for upload and download .