Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Remove files from folder in sftp

 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
 
Paul Clapham
Sheriff
Posts: 21126
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic