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了,你自己设置定时器到时候重新调用呗

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog