Ftpclient retivefileStream [Vans]JAVA

Программисты JAVA общаются здесь
Anonymous
Ftpclient retivefileStream [Vans]

Сообщение Anonymous »

У меня есть локальный FTP -сервер (созданный с помощью Filezilla Server), и есть несколько файлов XLS. Мне нужно вернуть поток ввода файла в мое приложение Java, чтобы я мог проанализировать данные и т. Д. мог найти, и ничто не помогло мне. Это действительно раздражает, и я бы хотел некоторую помощь, если это возможно.public FTPwrapper(){

ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Properties props = (Properties) context.getBean("ftp_props");

this.FTPhost = props.getProperty("host");
this.FTPuser = props.getProperty("user");
this.FTPpass = props.getProperty("pass");
this.FTPport = Integer.parseInt(props.getProperty("port"));
this.filesPath = props.getProperty("filesPath");
//start ftp connection
try {
client.connect(this.FTPhost, this.FTPport);
client.login(this.FTPuser, this.FTPpass);
client.setBufferSize(1024 * 1024);
client.enterLocalPassiveMode();
client.setFileType(FTP.BINARY_FILE_TYPE);
} catch (IOException e) {
e.printStackTrace();
}
}
< /code>

public InputStream returnFileStream(String FileName){

InputStream inputstream = null;

try {
String remoteFile = this.filesPath+FileName;
inputstream = client.retrieveFileStream(remoteFile);
client.completePendingCommand();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (client.isConnected()) {
client.logout();
client.disconnect();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}

return inputstream;
}
< /code>

public static void main(String[] args){
FTPwrapper ftp = new FTPwrapper();
InputStream inputstream = ftp.returnFileStream("data.xls");
}
< /code>

FPT log:
...login commands...
227 Entering Passive Mode
RETR data.xls
50 Opening data channel for file download from server of "/data.xls" //Hangs...
< /code>
После FTP -подключения Наконец -то время времени я получаю исключение Java: < /p>
java.io.IOException: Your file contains 383 sectors, but the initial DIFAT array at index 4 referenced block # 505. This isn't allowed and your file is corrupt
at org.apache.poi.poifs.storage.BlockAllocationTableReader.(BlockAllocationTableReader.java:103)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.(POIFSFileSystem.java:151)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.(HSSFWorkbook.java:322)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.(HSSFWorkbook.java:303)
< /code>
Я предполагаю, что это исключение заключается в том, что возвращается только часть моего файла XLS. Итак, это моя проблема. Есть идеи, как это решить?

Подробнее здесь: https://stackoverflow.com/questions/254 ... ream-hangs

Вернуться в «JAVA»