Error on the remote server: 227 Entering Passive Mode(xxx,xxx,xxx,xx)

2.5k Views Asked by At

I tried to download a .bak file from the FTP and save it into a local directory in my pc.

This is my code:

 Try
        My.Computer.Network.DownloadFile("ftp://nameOfServer/file.bak", "C:\Users\Admin\Documents\BackUp\file.bak", "user", "password")

    Catch ex As Exception
        MessageBox.Show(ex.Message, "Error")
    End Try

When I execute the code I get this error:

Error on the remote server: 227 Entering Passive Mode(xxx,xx,xxx,xxx,xxx,xx)

I know that I need to change it to active mode, but I can´t find a way works correctly with my code. How can I solve that? thanks

1

There are 1 best solutions below

2
On

You should make sure you are downloading the files correctly by following this older edit.

After some fiddling around to recreate the issue, the issue was solved using the following code

Dim username As String = "username"
Dim password As String = "password"
Dim address As String = "address"
Dim file As String = "file"
Dim outputFile As String = "outputFile"
My.Computer.Network.DownloadFile("ftp://" + username + ":" + password + "@" + address + "/" + file, outputFile)

Or the following was more concisely able to solve the issue

My.Computer.Network.DownloadFile("ftp://username:password@address/file", "outputLocation")

But another possible cause for your problems may have been simply caused by the output directory being missing, or more likely write protected (either by security policies or folder settings).

Finally if you have everything correct code and file-structure wise, I would advise contacting the ftp provider, and make sure the ftp server is configured and optimized properly for your use. If you cannot contact your ftp provider for help yet you can access your ftp settings, I would recommend disabling passive mode all-together for your ftp server at your own risk.