Question

I'm getting errors when trying to upload a file to FTP Server with the next VB.NET code:

Dim miUri As String = "ftp://ftp.mydomain.com/folder/file.jpg"
Dim miRequest As Net.FtpWebRequest = Net.WebRequest.Create(miUri)
miRequest.Credentials = New Net.NetworkCredential("user", "pass")
miRequest.Method = Net.WebRequestMethods.Ftp.UploadFile
Try
    Dim bFile() As Byte = System.IO.File.ReadAllBytes("C:\carpeta\fichero.jpg")
    Dim miStream As System.IO.Stream = miRequest.GetRequestStream()
    miStream.Write(bFile, 0, bFile.Length)
    miStream.Close()
    miStream.Dispose()
Catch ex As Exception
    Throw New Exception(ex.Message & ". El Archivo no pudo ser enviado.")
End Try

ex.Message = "Error on remote server: 227 Entering Passive Mode (x,x,x,x,21,183). ." ex.InnerException.Message = System.Net.Sockets.SocketException = {"A socket operation was attempted to an unreachable network x.x.x.x:5557"}

The line of code that throws the exception is:

Dim miStream As System.IO.Stream = miRequest.GetRequestStream()

POINTS:

  • If I try to connect by FileZilla or other FTP Client, I can connect without problems.

  • If I disable the antivirus, I can connect without problems.

  • Before somebody says something related to the firewall...

IF THE ANTIVIRUS IS ON, AND I CONNECT BY FILEZILLA, I CAN CONNECT WITHOUT PROBLEMS.

¿Where is the problem? ¿What I have to do in my code to get it run with the antivirus ON? If FileZilla can, I also have to be able...

Thanks a lot for your replies. Regards,

Was it helpful?

Solution

Sorry for the issue.

Finally it was because of the antivirus version I had installed.

Even putting the application as a trusted application, antivirus continued blocking the application.

I installed another version of the same antivirus and everything works fine.

Regards.

OTHER TIPS

"A socket operation was attempted to an unreachable network x.x.x.x:5557"

means that the server could not be reached. There are a number of reasons that could cause this issue.

  1. The server is down.
  2. Your computer is blocking the server connection incoming / outgoing (firewall)
  3. Unreliable internet access
  4. You mis-configured your connection string (the server string)

Essentially the issue most users will experience is that their firewall is blocking access to their FTP connection request. To fix this you must allow the application through your file wall.

-Cheers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top