-2

I am trying to connect my app to read a document hosted in my FTP server, I am using FileZilla, my app is hosted in Azure. But it seems it cannot connected. I have a public IP, in localhost my app runs fine but when it's online it failed. This is the code I am using to connect the app with my FTP server.

public static void getExcelFromFTP(string destinationFile)
    {

        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(@"ftp://100.100.100.0/folder/file.xlsx");

        request.KeepAlive = true;
        request.UseBinary = true;

        request.Credentials = new NetworkCredential(@"username", "password");//FTP Server credentials
        request.Method = WebRequestMethods.Ftp.DownloadFile;




        Stream reader = request.GetResponse().GetResponseStream();
        FileStream fileStream = new FileStream(destinationFile, FileMode.Create);

        int bytesRead = 0;
        byte[] buffer = new byte[2048];
        while (true)
        {
            bytesRead = reader.Read(buffer, 0, buffer.Length);

            if (bytesRead == 0)
                break;

            fileStream.Write(buffer, 0, bytesRead);
        }
        fileStream.Close();

    }

Can somebody help me out with this issue? Thanks in advance.

Lanshore
  • 43
  • 1
  • 1
  • 9
  • who hosts the ftp server? – BugFinder Mar 14 '16 at 14:53
  • I did it, using a public IP, I installed a fileZilla server in the computer I am using as server. – Lanshore Mar 14 '16 at 14:58
  • Are you sure theres no firewall between you and the outside world - eg no windows firewall, no router acting as firewall? try https://ftptest.net/ – BugFinder Mar 14 '16 at 15:00
  • I tested with the protocol: Explicit FTP over TLS, and it showed me the following: Make sure your server allows FTP over TLS and has a valid certificate configured. Some stateful firewalls filter the AUTH command. If that should be the case, replace the faulty firewall. – Lanshore Mar 14 '16 at 15:11
  • You might need to add an endpoint for the FTP ports in the Azure Management Portal. You'll need to allow traffic on ports 20 and 21. If the app is running on an Azure VM, you add that to the VM settings. – NickT Mar 14 '16 at 15:11
  • Also, there are 3 options for this. I do not know exactly what should use for this. I am relative new on FTP. – Lanshore Mar 14 '16 at 15:12
  • What is the exception you are getting? Show its callstack. – Martin Prikryl Mar 14 '16 at 15:40
  • @NickT & BugFinder The OP already stated that the code works on the dev machine. So it cannot be a firewall issue. – Martin Prikryl Mar 14 '16 at 15:42
  • if it cant connect at all, it suggests theres a firewall somewhere.. – BugFinder Mar 14 '16 at 15:53
  • @BugFinder OK, but the problem cannot be with the Azure firewall as the NickT suggested. – Martin Prikryl Mar 14 '16 at 16:32

1 Answers1

-1

The only thing what I had to it was to make sure that links were written correctly at the moment of attach files to the email.

Lanshore
  • 43
  • 1
  • 1
  • 9