ftp下载文件,出现Connection reset错误,而ftpbiede
代码如下:
//******************建立连接
FtpClient aftp = new FtpClient(strFTPAddress, Integer.parseInt(strFTPPort));
aftp.login(strFTPUser, strFTPPass);
aftp.binary();
aftp.cd(strFtpSourcesMainDir);
log.info("0\t连接FTP服务器:" + strFTPAddress + " 成功!");
//******************下载文件
String _strSourceFileName = "remotefile";
TelnetInputStream fget=aftp.get(_strSourceFileName);//设置源文件,错误在此发生
java.io.DataInputStream puts = new java.io.DataInputStream(fget);
String strTargetPathFileName = strPhyPath+"/upload/"+_strSourceFileName;
java.io.File fi = new java.io.File(strTargetPathFileName);//设置目的文件
if(fi.exists()){//若文件存在则删除
fi.delete();
}
java.io.RandomAccessFile getFile = new java.io.RandomAccessFile(fi,"rw");
getFile.seek(0);
int ch;
while ((ch = puts.read()) >= 0) {
getFile.write(ch);
}
getFile.close();//关闭文件保存
fget.close();//下载完毕
aftp.closeServer();