import com.enterprisedt.net.ftp.FTPTransferType;
import com.enterprisedt.net.ftp.FTPConnectMode;
import com.enterprisedt.net.ftp.FTPMessageListener;
import com.enterprisedt.net.ftp.*;
import com.enterprisedt.net.ftp.FTPFile;
import java.util.logging.*;
import java.util.*;
class FTPmine
{ private static final Logger LOGGER = Logger.getLogger(FTPmine.class.getName());
//Logger
private static Logger log = Logger.getLogger(FTPmine.class.getName());
public static void main(String args[])
{
try
{
FTPmine fu=new FTPmine();
FTPClient fc=null;
if(args[0].equals("1"))
{
fc=fu.getFTPClient("felog-w2k8","viswesh","viswesh");
}
String[] arr=fc.dir();
System.out.println("-->"+fc.getControlEncoding()+fc.pwd());
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i]);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static FTPClient getFTPClient(String hostName, String userName, String password)
throws Exception {
log.info("Connecting");
try {
FTPClient ftp = new FTPClient();
if(!ftp.connected())
{
ftp.setControlEncoding("utf-8");
System.out.println("encoding set da");
ftp.setRemoteHost(hostName);
ftp.connect();
}
else
{
System.out.println("encoding notset");
}
LOGGER.log(Level.FINER," FTP client {0}",ftp);
FTPMessageCollector listener = new FTPMessageCollector();
ftp.setMessageListener(listener);
loginFTPClient(userName, password,ftp);
// set up passive ASCII transfers
log.info("Setting up Active, BINARY transfers");
ftp.setConnectMode(FTPConnectMode.ACTIVE);
ftp.setType(FTPTransferType.BINARY);
return ftp;
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
private static void loginFTPClient(String user, String password,FTPClient ftp)
throws Exception {
// login
log.info("Logging in");
ftp.login(user, password);
}
}