我正在使用以下代码上传文件。它工作正常,但问题是在上传任意文件的过程中它被挂起(不知道是什么原因)。
- 可能是文件太长。
- 可能是连接无法正常工作。
但它仍然挂起,最后我必须手动终止它。因此,如果有任何问题,那么我如何才能识别超时并不重要,无论什么原因只是跳过该文件并出现一些错误。
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect("32.178.10.121");
client.login("XXX", "XXX");
//
// Create an InputStream of the file to be uploaded
//
File f = new File("D:\\FileFolder");
if (f.isDirectory())
{
File[] listFiles = f.listFiles();
for (int i = 0; i < listFiles.length; i++)
{
String filename = listFiles[i].getName();
fis = new FileInputStream(filename);
client.storeFile(filename, fis);
}
}
//
// Store file to server
//
client.logout();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}