1
I have an executable that sends a . CSV file via FTP to my client.
Running on my local machine works smoothly but when runs on my client’s server does not work.
Every time I fall in line
request.GetRequestStream()
get the error message
Unable to connect to the remote server
Follow the code of 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 have access to FTP address for upload and download.
There is no way to help you without knowing the details of the machine. Check firewall, proxy these things. If the firewall have locking the doors between 60000 and 61000 that’s the problem.
– Jéf Bueno
Excuse my ignorance, if the potas between 60000 and 61000 were blocked, Filezila would not be able to connect?
– Junior Torres
Depends on the rules of firewall. May be locked and have a rule releasing all the pro ports Filezilla.
– Jéf Bueno
I created new rules for the port range. I checked and the Firewall state of the profile is Off. Continues with the same error. some other hint?
– Junior Torres
Specific no. Try opening FTP by browser also, check if there is no restriction with your application.
– Jéf Bueno
tbm I have access through the browser.
– Junior Torres
What shows the stacktrace?
– Jéf Bueno
Once it enters the Getrequeststream() line I have the Exception "Unable to connect to the remote server " I tried to get the Innerexception log but it comes null
– Junior Torres
And the stacktrace?
– Jéf Bueno
Ql the ftp address value in both cases?
– Rovann Linhalis
@jbueno comes null
– Junior Torres
Includes a line and now stacktrace returns at System.Net.Ftpwebrequest.Chekerror()
– Junior Torres