0
我有一個只有List和Put權限的FTP服務器。但沒有刪除,覆蓋和重命名權限。嘗試使用FTP傳輸文件時文件覆蓋問題
現在,當我嘗試傳輸文件,使用簡單的FTP使用下面的實現
private boolean sendFileStreamHelper(InputStream inputStream, String nameOfFileToStore, String filetransferDestFolder) throws FileTransferException {
Log.info("Inside SendFile inputstream method to trasport the input stream of file " + nameOfFileToStore + " data to " + filetransferDestFolder);
BufferedOutputStream os = null;
FileObject fo = null;
try {
fo = getFileObject(nameOfFileToStore, filetransferDestFolder, ftpAuthDetails.getServerName(), ftpAuthDetails.getUsername(), ftpAuthDetails
.getPassword(), ftpAuthDetails.getPort());
fo.createFile();// create a file in the remote to transfer the file
os = new BufferedOutputStream(fo.getContent().getOutputStream());
FileUtil.readStream(inputStream, os);
return true;
} catch (Exception ex) {
Log.error("File transfer exception occurred while transferrig the file " + nameOfFileToStore + " to " + filetransferDestFolder, ex);
throw new FileTransferException(ex);
} finally {
if (os != null) {
try {
os.flush();
os.close();
} catch (IOException e) {
Log.warn(getClass(), " Error while closing the buffer output stream", e);
}
}
if (fo != null) {
try {
fo.close();
} catch (IOException e) {
Log.warn(getClass(), " Error while closing the File object", e);
}
}
closeCache(); // Close the VFS Manager instance
}
}
在上面的代碼,該文件是在遠程使用文件對象實例創建的。稍後我正在嘗試用Buffered流寫入文件。在這裏系統的行爲就好像它正在寫入已經創建的文件一樣,因爲我的服務器沒有任何覆蓋權限,會引發以下錯誤。
29 Jul 2012 21:03:06 [ERROR] FC_ClusteredScheduler_Worker-2(1) com.abc.filetransfer.FileTransferClient - .sendFileStreamHelper(FileTransferClient.java:170) - File transfer exception occurred while transferrig the file *******.txt to/ex-org.apache.commons.vfs2.FileSystemException: Could not write to "ftp://******:***@***.***.***.***/*********.txt"
org.apache.commons.vfs2.FileSystemException: Could not write to "ftp://******:***@***.***.***.***/*********.txt".
at org.apache.commons.vfs2.provider.AbstractFileObject.getOutputStream(AbstractFileObject.java:1439)
at org.apache.commons.vfs2.provider.DefaultFileContent.getOutputStream(DefaultFileContent.java:461)
at org.apache.commons.vfs2.provider.DefaultFileContent.getOutputStream(DefaultFileContent.java:441)
at com.abc.filetransfer.FileTransferClient.sendFileStreamHelper(FileTransferClient.java:164)
at com.abc.filetransfer.FileTransferClient.sendFile(FileTransferClient.java:131)
at com.abc.filetransfer.FileTransferClient.sendFile(FileTransferClient.java:103)
at com.abc.filetransfer.client.FTPTransferClient.sendFile(FTPTransferClient.java:65)
Caused by: org.apache.commons.vfs2.FileSystemException: Cant open output connection for file "ftp://******:***@***.***.***.***/*********.txt".
Reason: "**550 File unavailable. Overwrite not allowed by user profile**^M
at org.apache.commons.vfs2.provider.ftp.FtpFileObject.doGetOutputStream(FtpFileObject.java:648)
at org.apache.commons.vfs2.provider.AbstractFileObject.getOutputStream(AbstractFileObject.java:1431)
請讓我知道我可以使用文件對象,處理文件傳輸,使得兩個文件創建和寫入流應立即發生。