代码如下: //******************建立连接
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();
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();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货