on 12-16-2009 8:54 AM
Hi All
Code to establish a connection with ftp and then delete the contents of file
Through this code i am trying to delete the contents of a file at FTP location
FileLocation = new URL("ftp://+username:password@IPAddress/Directory" +"/"+fileName+ "");
URLConnection uc = FileLocation.openConnection() ; // to establish connection with FTP server using URL
uc.setDoOutput(true);
OutputStream out = uc.getOutputStream();
Audit.addAuditLogEntry(auditMKey,AuditLogStatus.SUCCESS,"CustomModule :: file"+out);
out.flush();//to make the file empty
out.close();//close the file so that connection can be terminated
Output out is not getting any value (not getting initialized)
Please let me know the reason.
Regards
Dheeraj Kumar
Hi Dheeraj,
I think you just need to write something to the output stream. This worked for me:
URL url = new URL("ftp://<user>:<pass>@<host>:<port>/<pathToFile>");
URLConnection urlConn = url.openConnection() ;
urlConn.setDoOutput(true);
OutputStream out = urlConn.getOutputStream() ;
out.write(new byte[0]);
out.flush();
out.close();
If you need to do more than this perhaps look at: http://commons.apache.org/net/
-Russ
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.