crazyly_k 2015-04-22 01:11 采纳率: 0%
浏览 5920

java ftp上传过程中服务器断连后怎么重新连接

public boolean upload(File file,XML xml1) throws Exception{
try {
bstate=0;
while(ftp==null || bstate<2)
{
sleep(500);
bstate=connect(xml1);
if(ftp==null || bstate<2){
System.out.println("连接服务器失败,请检查服务器是否开启!");
}
}
if(file.isDirectory()){

ftp.makeDirectory(file.getName());

ftp.changeWorkingDirectory(file.getName());

String[] files = file.list();

for (int i = 0; i < files.length; i++) {

File file1 = new File(file.getPath()+"\"+files[i] );

if(file1.isDirectory()){

upload(file1,xml1);

ftp.changeToParentDirectory();

}else{

File file2 = new File(file.getPath()+"\"+files[i]);

FileInputStream input = new FileInputStream(file2);

ftp.storeFile(file2.getName(), input);

input.close();

}
}
}else{

File file2 = new File(file.getPath());

FileInputStream input = new FileInputStream(file2);

ftp.storeFile(file2.getName(), input);
bsc=true;
input.close();

}

        ftp.logout();
    } catch (Exception e) {
        e.printStackTrace();
    }finally {
        try {
            ftp.disconnect();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    } 
    return bsc;
} 


    程序执行到粗体字除,也就是上传过程中,服务器断开了要怎么设置隔几分钟重新连接一次
  • 写回答

2条回答 默认 最新

  • threenewbee 2015-04-22 02:50
    关注

    断开了进入你的catch了,你自己设置定时器到时候重新调用呗

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大