【发布时间】:2017-11-20 12:26:48
【问题描述】:
我有一个文件要上传(比如abc.pdf)。我第一次想将此文件作为临时文件上传(比如abc.pdf.temp)。然后,如果文件成功传输(完全传输),那么我需要将其重命名为其原始名称(abc.pdf)。但是如果文件没有完全传输,那么我需要删除我最初上传的临时文件,因为我不想在服务器中保留损坏的文件。使用这个 JSch 库可以做到这一点吗?下面是示例代码。这段代码是否有意义?
示例代码:
originalFile = 'abc.pdf';
tempFile = 'abc.pdf.temp';
fileInputStream = createobject("java", "java.io.FileInputStream").init('C:\abc.pdf');
SftpChannel.put(fileInputStream,tempFile);
// Comparing remote file size with local file
if(SftpChannel.lstat(tempFile).getSize() NEQ localFileSize){
// Allow to Resume the file transfer since the file size is different
SftpChannel.put(fileInputStream,tempFile,SftpChannel.RESUME);
if(SftpChannel.lstat(tempFile).getSize() NEQ localFileSize){
// Check again if the file is not fully transferred (During RESUME) then
// deleting the file since dont want to keep a corrupted file in the server.
SftpChannel.rm(tempFile);
}
}else{//assuming file is fully transferred
SftpChannel.rename(tempFile ,originalFile);
}
【问题讨论】:
-
这不是代码编写服务。您在实施此操作时遇到什么具体问题?你已经尝试了什么?向我们展示您的代码。
-
我可以使用 superuser.com 获取此信息吗?
-
我不明白。你有一个编程问题。所以你应该在这里问。但是您需要在本网站范围内提出问题。这应该包括您当前的代码和您的具体问题。你没有问具体的问题。您要求我们为您完成工作。
-
通过更新原始问题提供了代码。
标签: java coldfusion sftp jsch