-1
I use FTP, to download files to my system, it is a very simple code, using FTP REQUEST, however I am facing problems with who uses the NET provider(and some others however the Net is more evident)
try
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(url);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(usuario,senha);
request.UseBinary = true;
request.UsePassive = true;
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
{
using (Stream rs = response.GetResponseStream())
{
using (FileStream ws = new FileStream(local, FileMode.Create))
{
byte[] buffer = new byte[2048];
int bytesRead = rs.Read(buffer, 0, buffer.Length);
while (bytesRead > 0)
{
ws.Write(buffer, 0, bytesRead);
bytesRead = rs.Read(buffer, 0, buffer.Length);
}
}
}
}
}
catch
{
throw;
}
In the request.Getresponse(), Exception returns, Time Limit of Operation Reached, I ran Telnet to test port 21, and it worked. So I believe there’s something I can do to fix this problem.
It could be the firewall that blocked your C# program to access other domains and ports. There’s no way to know. Ran telnet and C# on the same machine?
– Guilherme Nascimento
@Guilhermenascimento with the same machine using a different internet than certain, so it is not the Windows Firewall, perhaps the firewall in conjunction with the Network?
– Andrew Alex
No, I believe it’s the machine’s firewall, when it accesses a WIFI network it can enter Public Network mode and other Wifi in particular network, which changes the default rules of the firewall, but has no way of stating. Anyway the problem doesn’t seem to be in the code.
– Guilherme Nascimento
I ran Telnet, and C# on the same machine and with the same internet.
– Andrew Alex
In win 10 each wifi network (SSID) can be linked to a type of network, private, company or publish, so if it worked on another network is pq should be as private and if it does not work on the current network is pq should be as published, but this is not a matter of the network but of the firewall rules of each network, of which you can "customize", and probably the first time you ran your C# vc must have applied some permission of a windows window that appeared and did not notice
– Guilherme Nascimento
@Guilhermenascimento I will try to verify this aspect.
– Andrew Alex
If you have someone who has knowledge of networks (even Windows) there helps, it is good you learn, but if you do not know or risk a lot to move, ask someone to do it, although it is not very complicated is a dangerous place to move, can cause a huge problem
– Guilherme Nascimento
Read the documentation in the part about DNS: https://docs.microsoft.com/pt-br/dotnet/api/system.net.ftpwebrequest.timeout?view=netframework-4.8#coment-rios
– Bruno Warmling
I will read @Brunowarmling, I will also try to change the Timeout to see if there is any difference in the error return.
– Andrew Alex
According to what it says there,
Timeout
is infinite, so could be problem when trying to solve the DNS... Try using direct IP to see if the same problem occurs.– Bruno Warmling
@Brunowarmling I will test switch to ip, too.
– Andrew Alex
@Brunowarmling killed the riddle, the problem is in trying to solve the DNS, I will do some more tests and put the solution.
– Andrew Alex