InputStream is = null;
byte[] data = xDto.toString().getBytes();
尝试 {
is = new BufferedInputStream(new ByteArrayInputStream(data));
int status = SFTP.sendFile(is, nameOfFile, destFolder, host, username, password);
if(FileTransferStatus.SUCCESS == status){
System.out.println(" got sftp-ed successfully to folder "+destFolder);
}
else if(FileTransferStatus.FAILURE == status){
System.out.println("Fail to sftp to folder "+destFolder);
}
} catch (FileTransferException e) {
e.printStackTrace();
}
错误是:
com.zehon.exception.FileTransferException: org.apache.commons.vfs.FileSystemException: Could not create file "(path of file)".
at com.zehon.FileTransferClient.sendFileStreamHelper(FileTransferClient.java:316)
at com.zehon.FileTransferClient.sendFile(FileTransferClient.java:287)
at com.zehon.sftp.SFTPClient.sendFile(SFTPClient.java:281)
at com.zehon.sftp.SFTP.sendFile(SFTP.java:110)
at com.stud.main.CreateFileUsingFtp.main(CreateFileUsingFtp.java:55)
Caused by: org.apache.commons.vfs.FileSystemException: Could not create file "(path of file)".
at org.apache.commons.vfs.provider.AbstractFileObject.createFile(AbstractFileObject.java:916)
at com.zehon.FileTransferClient.sendFileStreamHelper(FileTransferClient.java:301)
... 4 more
Caused by: org.apache.commons.vfs.FileSystemException: Could not create folder "(folder name)".
at org.apache.commons.vfs.provider.AbstractFileObject.createFolder(AbstractFileObject.java:969)
at org.apache.commons.vfs.provider.AbstractFileObject.createFolder(AbstractFileObject.java:952)
at org.apache.commons.vfs.provider.AbstractFileObject.getOutputStream(AbstractFileObject.java:1390)
at org.apache.commons.vfs.provider.AbstractFileObject.getOutputStream(AbstractFileObject.java:1353)
at org.apache.commons.vfs.provider.AbstractFileObject.createFile(AbstractFileObject.java:906)
... 5 more
Caused by: 3: Permission denied
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2289)
at com.jcraft.jsch.ChannelSftp.mkdir(ChannelSftp.java:1699)
at org.apache.commons.vfs.provider.sftp.SftpFileObject.doCreateFolder(SftpFileObject.java:195)
at org.apache.commons.vfs.provider.AbstractFileObject.createFolder(AbstractFileObject.java:958)
... 9 more