1

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)

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
faycal81
  • 13
  • 5

1 Answers1

1

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().

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