0

My scenario as follows: One java program is updating some random files to a SFTP location.

My requirement is as soon as a file is uploaded by the previous java program, using java I need to download the file. The files can be of size 100MB. I am searching for some java API which is helpful in this way. Here I even don't know the name of files. But I can keep a regular expression for this. A same file can be uploaded by previous program periodically. Since file size is high I need to wait until the complete file to be uploaded.

I used Jsch to download files, but I am not getting how to poll using jsch.

  • Did u get to look at this ? http://stackoverflow.com/questions/9283433/file-directory-synchronization-in-java-using-jsch – nagamanojv Jan 23 '15 at 10:30

1 Answers1

2

Polling

All you can do is to keep listing remote directory periodically, until you find a new file. There's no better way with SFTP. For that you obviously use ChannelSftp.ls().

Regarding selecting files matching certain pattern, see:
JSch ChannelSftp.ls - pass match patterns in java

Waiting until the upload is complete

Again, there's no support for this in widespread implementations of SFTP.

For details, see my answer at:
SFTP file lock mechanism.

Community
  • 1
  • 1
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992