File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes Remove files from folder in sftp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Remove files from folder in sftp" Watch "Remove files from folder in sftp" New topic

Remove files from folder in sftp

Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362

i need to remove all files from one folder in sftp from java? please let me know which api is best to do this task?

Thanks in advance
Ganesh Kumar CH

SCJP5 and SCWCD1.5
Think Twice Act Wise...
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

I don't know how many SFTP APIs you were considering in your review, but removing a file is a very simple operation and any API which supports that operation would be suitable. Looking for the "best" at this task isn't a good use of anybody's time.
Richard Tookey

Joined: Aug 27, 2012
Posts: 1166

There is no single command in version 3 of the SFTP protocol (which is what openssh conforms to) for removing the content of a directory so that any Java library that does this in one command will internally need to first list all the files in the directory and then iterate over the list removing each one in turn. This should take no more than half a dozen lines of code for you to write yourself and unless the Java library does the deletes asynchronously (which is what the protocol allows) your code will be as fast as any other.
I agree. Here's the link:
subject: Remove files from folder in sftp
It's not a secret anymore!