• Post Reply Bookmark Topic Watch Topic
  • New Topic

removing lock on the file to delete.

 
gman gman
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am running into a problem after FTP the file. it wont delete it unless i close tomcat. i get the error that the file is being used. although i am closing the connection. here is the code.
public void upload(String remotedir, String file, String localdir, boolean asc) throws IOException {
//Check if file is OK
File ftpFile = new File(localdir + "\\" + file);
if (!ftpFile.isFile()) {
throw new IOException("FTP file does not exist.");
}
RandomAccessFile raf = new RandomAccessFile(ftpFile,"r");
ftpSetDir(remotedir);
ftpSetTransferType(asc);
dsock = ftpGetDataSock();
OutputStream os = dsock.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
ftpSendCmd("STOR "+file);
int idata = 0;
while (true) {
idata = raf.read();
if (idata != -1) {
dos.writeByte(idata);
} else {
break;
}

}
//System.err.println("Done creating a file");
dos.flush();
dos.close();
ftpLogout();
}

private void ftpLogout() {
try {
pos.print("BYE\r\n");
pos.flush();
pos.close();
dcis.close();
csock.close();
dsock.close();
} catch (IOException e) {
System.err.println("Error closing FTP: " + e.getMessage());
}
}
public void FTPConnect(String server, String user, String pass) {
try {
ftpConnect(server);
ftpLogin(user, pass);
//System.out.println("connection made");
} catch(IOException ioe) {
System.err.println("Failed with connection to Server");
}
}
I am connecting first, then i call the upload method then i delete the file...
any ideas would help please... thanx
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!