Hi All,
I am new to edtftp. I have a fair amount of Java experience, and I am making a custom class, extending the FTPClient class shipped with the edtftpj software. Here are the relevant methods of my class:
public class FTPService extends FTPClient{
static Logger log = Logger.getLogger(FTPService.class);
FTPMessageCollector listener;
/**
* Default Constructor
*
*/
public FTPService(){
log.debug("FTPService() created.");
}
/**
* Sets up FTP client
* @param host
* @throws Exception
*/
public void setup(String host) throws Exception{
// Set up client
setRemoteHost(host);
listener = new FTPMessageCollector();
setMessageListener(listener);
}
/**
* Connects to client
* @param client
* @throws Exception
*/
public void connect(String client) throws Exception{
log.info("Connecting to " + client);
connect();
}
/**
* Logs into remote system
* @param user
* @param pass
* @throws Exception
*/
public void loginInfo(String user, String pass) throws Exception{
log.info("Logging in...");
login(user, pass);
}
/**
* Changes reemote directory to supplied directory
* @param chdir
* @throws IOException
* @throws FTPException
*/
public void changeDir(String chdir) throws IOException, FTPException{
log.info("changing directory to "+ chdir);
chdir(chdir);
}
/**
* Set the type of file transfer, and the connection mode.
* @param connectMode
* @param setType
*/
public void setParameter (String connectMode, String type) throws Exception{
log.debug("Setting up transfers");
FTPConnectMode mode;
FTPTransferType transType;
//What kind of connection is it?
if(connectMode.equalsIgnoreCase("actv"))
mode = FTPConnectMode.ACTIVE;
else
mode = FTPConnectMode.PASV;
//now, set the connection mode based on what's passed into method.
setConnectMode(mode);
//What kind of transfer is it?
if(type.equalsIgnoreCase("ascii"))
transType = FTPTransferType.ASCII;
else
transType = FTPTransferType.BINARY;
//Set the transfer type based on what's passed into the method.
setType(transType);
}
/**
* Puts the specified file referenced by the full path, on the remote server
* with the same name.
* @param filename
* @param remoteName
* @throws Exception
*/
public void putFile(String filename, String remoteName) throws Exception{
// copy file to server
log.info("Putting file: " + filename);
put(filename, remoteName);
}
public void getDir() throws Exception{
// get directory and print it to console
log.debug("Directory after put");
String[] files = dir(".", true);
for (int i = 0; i < files.length; i++)
log.debug(files[i]);
//return files;
}
public void closeConnection() throws Exception{
// Shut down client
log.info("Quitting client");
quit();
}
public String getMessage(){
String messages = listener.getLog();
log.debug("Listener log:");
log.debug(messages);
return messages;
}
I call the methods from another class, running on a timer. Here are the method calls:
service = new FTPService();
/*
* The next three lines initialize, connect and log into
* the ftp host.
*/
service.setup(recip.getHostname());
service.connect(recip.getCompanyIdentifier());
service.loginInfo(recip.getUsername(), recip.getPassword());
//what kind of system am I connected to?
logger.info(service.system());
//Am I actually connected?
boolean b = service.connected();
logger.info("connected: " + b);
//set my transfer type and change directories to the target dir
service.setParameter(recip.getConnectMode(), "ascii");
service.changeDir(recip.getDestinationDir());
service.getDir();
//now send the files...
for (Iterator it = a.iterator (); it.hasNext (); ) {
logger.info("Ready to transfer file...");
File f1 = (File) it.next ();
logger.info("File: " + f1.getName());
service.putFile(f1.getAbsolutePath(), f1.getName());
}
but I am at a loss to explain the following issue When I attempt to transfer a file, I get the following output:
...
06 Jul 2007 - 17:23:54 [Timer-0] INFO com.sm.directoryassistance.Reader - There are 15 files in /Export/
06 Jul 2007 - 17:23:54 [Timer-0] INFO com.sm.ftp.FTPService - Connecting to ThomsonWest
06 Jul 2007 - 17:23:54 [Timer-0] INFO com.sm.ftp.FTPService - Logging in...