Reputation: 13
I am trying to develop a program that is to retrieve a set of files from an SFTP server to another local directory.
I use JSch library for this.
The files are downloaded with the get
method.
ChannelSftp connection = connect(host, port, user, password);
connection.get(fileName, localFolder, null, mode);
The business requirement is that if the file is not completely downloaded, they can not retrieve from the local directory.
How can do we rename the file being downloaded in the local directory until the download is not finished?
After download is finished, we rename file with his real filename (filename of the server SFTP)
Upvotes: 1
Views: 2277
Reputation: 202222
Use a full file path in dst
argument of .get
, including a (temporary) file name, not just a directory path.
connection.get(fileName, localFolder + "/tempname", null, mode);
Rename the file after the .get
finishes, using File.renameTo()
.
Upvotes: 1