Question

I am trying to retrieve a file from an ftp server with anonymous authentication using java.net.URLConnection.

    try {
        url = new URL("ftp://ftp2.sat.gob.mx/Certificados/FEA/000010/000002/02/03/05/00001000000202030500.cer");
        URLConnection con = url.openConnection();

        InputStream in = con.getInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = in.read(buffer)) >= 0)
        {
            baos.write(buffer, 0, bytesRead);
        }
        baos.flush();
        arr = baos.toByteArray();

        in.close();
    } catch (Exception e) {
        throw new Exception("Error SAT: " + e.getMessage());
    }

The file i am trying to get is this, its in an anonymous authentication ftp site: ftp://ftp2.sat.gob.mx/Certificados/FEA/000010/000002/02/03/05/00001000000202030500.cer

But every time I get this error: Permission denied: Attempt to bind port without permission.

I am using GoogleAppEngine Java 1.7

Any kind of advise is welcome.

Was it helpful?

Solution

I'm not a Java guy, but I suspect you're trying to use "active" FTP, which is likely the default.

Active FTP works by binding to a port on the receiving computer (the client in this case) to which the sending server can connect to send the file; the port number is sent over in the get request. This doesn't work in many environments, e.g. NAT.

The usual solution is to use "passive" mode, which behaves more like HTTP and doesn't require any port binding. If there's a way in Java to twiddle that connection to use passive mode, it should bypass the permissions issue.

OTHER TIPS

Most likely you have a non billing-enabled app, according to this post and this AppEngine Socket Java API documentation you just have to enable billing, if you have no budget set the limits to $0.

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