FTPClient in passive mode

0

I'm having trouble trying to connect to FTP. For FileZila, it works normally .... but when I try for this code, it generates the following exception: j ava.net.BindException: Can not assign requested address: JVM_Bind The error occurs when I call ftp.connect (); I have tried to use FTP in passive mode, but I have not tried it, I tried to use it: enterRemoteActiveMode (), enterLocalPassiveMode (), enterLocalActiveMode () but nothing solved ..... anyone have any ideas? p>

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();
        }
        .....
        .....
        .....
    
asked by anonymous 20.07.2017 / 21:06

1 answer

0

I managed to resolve. I was using FTP in active mode :

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

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

if(!ftp.isConnected()){             
    //Faz conexão FTP               
    ftp.connect(destino, cdPortaFTP);
}           
ftp.enterLocalPassiveMode(); 
    
24.07.2017 / 18:36