两个工具类依赖的jar包:
FTPTool.java
public static void main(String[] args) throws Exception{ FTPTooL ftpTool = new FTPTooL(); FTPClient ftpClient = null; InputStream stream = null; stream = StreamTool.getStreamFromString(StreamTool.streamStr); try{ String host = "10.16.55.21";//ip int port = 21; //port String username = "zssys";//user String password = "zssys";//password ftpClient = ftpTool.createFtpClient(host, port, username, password,null,null); ftpTool.mkdir ("/home/zstest/dvlp/pic_test/underwrt_pic/test/", "123/456/789", ftpClient);//建目录 ftpTool.upload ("/home/zstest/dvlp/pic_test/underwrt_pic/test/", "D:/temp/","HousingEstateManagerment.rar", ftpClient);//上传 ftpTool.upload ("/home/zstest/dvlp/pic_test/underwrt_pic/test/", stream,"ddd.PNG", ftpClient);//上传 ftpTool.download ("/home/zstest/dvlp/pic_test/underwrt_pic/test/", "ddd.PNG", "D:/temp/haha/","download.PNG", ftpClient);//下载 ftpTool.delete ("/home/zstest/dvlp/pic_test/underwrt_pic/test/", "delete.txt", ftpClient);//删除 }catch(Exception e){ e.printStackTrace(); }finally{ ftpTool.disconnect(ftpClient); } }
SFTPTool.java
public static void main(String[] args) throws Exception{ SFTPTooL sfTool = new SFTPTooL(); Session session = null; ChannelSftp channel = null; InputStream stream = null; stream = StreamTool.getStreamFromString(StreamTool.streamStr); try{ String host = "10.15.22.120";//ip int port = 22; //port String username = "weblogic";//user String password = "weblogic";//password session = sfTool.getSession(host, port, username, password); channel = sfTool.getConnect(session); sfTool.mkdir ("/data/temp/test/", "123/888/789", channel);//建目录 sfTool.upload ("/data/temp/test/", "D:/temp/","HousingEstateManagerment.rar", channel);//上传 sfTool.upload ("/data/temp/test/", stream,"ddd.PNG", channel);//上传 sfTool.download ("/data/temp/test/", "download.txt", "D:/temp/haha/","download.txt", channel);//下载 sfTool.delete ("/data/temp/test/", "delete.txt", channel);//删除 }catch(Exception e){ e.printStackTrace(); }finally{ sfTool.disconnect(channel,session); } }
时间: 2024-10-06 02:13:07