Avatar of Dehankar
Dehankar

asked on 

how to check enterLocalActiveMode and enterLocalPassiveMode()

Dear Expert,
I want to connect with FTP server. I am using 'ftp.enterLocalPassiveMode(); ' for  listing files and directory. But sometime I want 'ftp.enterLocalActiveMode' . So  how I can use the conditionin my code for either enterLocalActiveMode Or  enterLocalPassiveMode .

FTPClient ftp = new FTPClient();
source = frmFtpFormS.getFileSource();
destination = rs.getProperty("file_destination");
server = frmFtpFormS.getServerName();
username = frmFtpFormS.getFtpUsername();
password = frmFtpFormS.getFtpPassword();
/*Connect through FTPServer instead of FTP Client */	
//ftp.setConnectTimeout(1000); // one second
ftp.connect(server);
ftp.login(username, password);//Login using Username and Password 
/* To check Connect */
int reply = ftp.getReplyCode();
 if(!FTPReply.isPositiveCompletion(reply)) {
 ftp.disconnect();
 System.err.println("FTP server refused connection.");
// System.exit(1);
// getFTPStatus1("disconnect");
 }
 else
 {
 //getFTPStatus1("connect");
 frmFtpFormS.setFtpcon("true");
// checkFtpCon="true";
 } 
ftp.changeWorkingDirectory(source);//change to the directory contaning files
String name = ftp.getSystemName();
/*
 * Mode to connect with FTP Server
 * 
 * */
//ftp.enterLocalPassiveMode(); 
ftp.enterLocalActiveMode();
String[] file1 = ftp.listNames();
FTPFile[] files = ftp.listFiles();// List the files in the directory
int l = files.length;

Open in new window

Java EEJava

Avatar of undefined
Last Comment
Dehankar

8/22/2022 - Mon