我用sun包做了个ftp上传,前面登录一切正常,当ftpClient.cd操作的的时候就抛出一下异常sun.net.ftp.FtpLoginException: Not logged in代码如下:
try {
log.logger.info("登录服务器" + ftpHost + "....." + new Date());
ftpClient = new FtpClient(ftpHost);
//ftpClient.openServer(ftpHost);
ftpClient.login(user, password);
} catch (Exception e) {
log.logger.info("登录失败....." + e.getMessage() + new Date());
e.printStackTrace();
}
log.logger.info("开始上传对账文件....." + new Date());
// ftpClient.sendServer("PORT");
ftpClient.cd(remotePath);
ftpClient.binary();
os = ftpClient.put(fileName);
File file_in = new File(localPath + fileName);
is = new FileInputStream(file_in);
byte[] bytes = new byte[1024];
int c;
while ((c = is.read(bytes)) != -1) {
os.write(bytes, 0, c);
}

解决方案 »

  1.   


    } catch (Exception e) {
    log.logger.info("登录失败....." + e.getMessage() + new Date());
    e.printStackTrace();
    }
    catch到异常就应该返回
    你登录失败后还继续执行后面的操作,没有意义,肯定失败
      

  2.   

    我知道是提示未登录,难道sun这个包未登录成功也不作任何提示,有没有方法判断是否登录成功?