Ftpclient in passive mode

Asked

Viewed 100 times

0

I have a problem trying to connect FTP. For Filezila, it works normally.... but when I try for this code snippet, it generates the following exception: jAva.net.Bindexception: Cannot assign requested address: Jvm_bind The error occurs when I call ftp.connect(); Searching for the solution, I saw that I had to use FTP in passive mode, but I could not, already tried to use: enterRemoteActiveMode(), enterLocalPassiveMode(), enterLocalActiveMode() but nothing solved.... anyone has any idea ?

try {
        this.beginTransaction(xxxxxxx);     

        //Configura Conexão FTP
        InetAddress localhost = xxxxx;
        InetAddress destino =xxxx; 
        cdPortaFTP = xxxxx;
        if(!ftp.isConnected()){             
            //Faz conexão FTP               
            ftp.connect(destino, cdPortaFTP, localhost, cdPortaFTP);
        }
        //ftp.enterRemoteActiveMode();
        //ftp.enterLocalPassiveMode();
        //ftp.enterLocalActiveMode();

        // verifica se conectou com sucesso e faz login
        if (FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
            ftp.login(xxxx,xxxx);                       
        } else {
            ftp.disconnect();
            throw new Exception();
        }
        .....
        .....
        .....
  • Does this error usually occur when the port you are accessing is already in use? Make sure there is nothing running on it. PS post error stacktrace

    • Stack Trace: java.net.Bindexception: Cannot assign requested address: Jvm_bind -at java.net.Plainsocketimpl.socketBind(Native Method) -at java.net.Plainsocketimpl.bind(Plainsocketimplsocket.java:402) -at java.net.Socket.bind(Socket.java:576) -at org.apache.Commons.net.Socketclient. _connect(Socketclient.java:241) -at org.apache.Commons.net.Socketclient.connect(Socketclient.java:226)

1 answer

0


I managed to fix it. I was using the FTP in active mode:

if(!ftp.isConnected()){                             
    ftp.connect(destino, cdPortaFTP, localhost, cdPortaFTP);
}
    ftp.enterLocalActiveMode(); 

When in fact, I needed to use the FTP in passive mode because they access the internet via firewall/Nat. And the passive also does not need the local bind. So I put in passive mode:

if(!ftp.isConnected()){             
    //Faz conexão FTP               
    ftp.connect(destino, cdPortaFTP);
}           
ftp.enterLocalPassiveMode(); 
  • Note: Doors below a thousand and little are restricted to administrators. So, use higher ports.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.