|
| |
精品推荐 |
 |
|
| |
|
|
|
|
java做的比较完善的FTP连接上传下载文件
|
日期:2004年9月24日 作者:清风网络学院 查看:[大字体
中字体 小字体]
|
a = "连接主机:"+hostname+"成功!"; System.out.println(a); } catch(FtpLoginException e){ a="登陆主机:"+hostname+"失败!请检查用户名或密码是否正确:"+e; System.out.println(a); //return false; } catch (IOException e){ a="连接主机:"+hostname+"失败!请检查端口是否正确:"+e; System.out.println(a); //return false; } catch(SecurityException e) { a="无权限与主机:"+hostname+"连接!请检查是否有访问权限:"+e; System.out.println(a); //return false; }
log(RWFileDir,a); return aftp; }
public void stop(String RWFileDir) { String message = ""; try { if(aftp!=null){ aftp.closeServer(); message = "与主机"+hostname+"连接已断开!"; System.out.println(message); log(RWFileDir,message); } } catch(IOException e) { message = "与主机"+hostname+"断开连接失败!"+e; System.out.println(message); log(RWFileDir,message); } }
public boolean downloadFile(String RWFileDir,String filepathname){ boolean result=true; String message = ""; if (aftp != null) { System.out.println("正在下载文件"+filepathname+",请等待...."); String badfile = filepathname.substring(filepathname.length()-4,filepathname.length()); String badlog = filepathname.substring(filepathname.length()-7,filepathname.length()); String baddir = ""; if ((badfile.compareTo(".bad") != 0) && (badlog.compareTo(".badlog") != 0)){ baddir = "subunsubtosp\\"; } else{ baddir = "bad\\"; } String strdir = "subunsubtosp\\"; //System.out.println(RWFileDir + baddir + filepathname); try{ //FtpClient fc=new FtpClient("192.168.0.56",2121); //fc.login("lee","lee"); int ch; File fi = new File(RWFileDir + baddir + filepathname); //aftp.cd(strdir); RandomAccessFile getFile = new RandomAccessFile(fi,"rw"); getFile.seek(0); TelnetInputStream fget=aftp.get(strdir+filepathname); DataInputStream puts = new DataInputStream(fget); while ((ch = puts.read()) >= 0) { getFile.write(ch);
} //s.delete();
fget.close(); getFile.close(); //fc.closeServer();
message = "下载"+filepathname+"文件到"+baddir +"目录成功!"; System.out.println(message); log(RWFileDir,message); } catch(IOException e){ message = "下载"+filepathname+"文件到"+baddir +"目录失败!"+e; System.out.println(message); log(RWFileDir,message); result = false ;
} } else{ result = false; } return result; }
public boolean uploadFile(String RWFileDir,String filepathname){
上一篇:用Struts开发国际化程序思路
下一篇:变量的变量,PHP 和 你
|
| java做的比较完善的FTP连接上传下载文件 相关文章: |
|
|
|
| java做的比较完善的FTP连接上传下载文件 相关软件: |
|
|
|
|