telnet--ftp-java_第1页
telnet--ftp-java_第2页
telnet--ftp-java_第3页
telnet--ftp-java_第4页
telnet--ftp-java_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、telnet连接步骤.telnet.TelnetClient1 new 一个TelnetClient赋值ip地址,port,超时时间TelnetClient tc=new TelnetClient();2读取telnet输入流, tc.setDefaultTimeout(10000);tc.connect(1, 23);3用inputstream和outputstream控制输入输出进行交互InputStream in=tc.getInputStream();OutputStream out=tc.getOutputStream();例子TelnetClient tc=new

2、TelnetClient();try tc.setDefaultTimeout(10000);tc.connect(1, 23);InputStream in=tc.getInputStream();OutputStream out=tc.getOutputStream();BufferedReader sin=new BufferedReader(new InputStreamReader(System.in);byte bs=new byte256;int i=0;while(i=in.read(bs)-1)String str=null;if(i=256)str=new

3、String(bs);elsebyte bs2=new bytei;for(int j=0;j-1|str.indexOf(assword:)-1)commond = sin.readLine();out.write(commond+n).getBytes(); out.flush();else/out.write( n).getBytes(); catch (SocketException e) / TODO Auto-generated catch blocke.printStackTrace(); catch (IOException e) / TODO Auto-generated c

4、atch blocke.printStackTrace();ftp连接.ftp.FTPClient;步骤:1建立连接FTPClient ftp = new FTPClient();ftp.connect(1, 21);ftp.login(itcc, itcc)2对目录里的文件进行修改,(上传,删除,重命名等)主要方法Rename(Stirng,String)Connect(String host,int port)Login(username,password)stroeFile系列代码FTPClient ftp = new FTPClient();try ftp.connec

5、t(1, 21);if (!ftp.login(itcc, itcc) System.out.println(Ftp登陆失败);elseftp.setFileType(.ftp.FTP.IMAGE_FILE_TYPE);ftp.storeUniqueFile(1.jpg,new FileInputStream(D:/1.jpg);if(ftp != null & ftp.isConnected()try ftp.disconnect(); catch (IOException e) catch (SocketException e) / TODO Auto-generated

6、catch blocke.printStackTrace(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();Ssh连接 ch.ethz.ssh2.Connection;1建立连接方式:authenticateWithDSA(String, String, String)authenticateWithKeyboardInteractive(String, InteractiveCallback)authenticateWithKeyboardInteractive(String, Stri

7、ng, InteractiveCallback)authenticateWithPassword(String, String)authenticateWithPublicKey(String, char, String)authenticateWithPublicKey(String, File, String)2执行命令得到一个session,通过session,输出命令,并得到返回Session s=conn.openSession();/ch.ethz.ssh2.Sessions.execCommand(command);InputStream stdout = new StreamG

8、obbler(s.getStdout();例子Connection conn = null;BufferedReader sin=new BufferedReader(new InputStreamReader(System.in);conn=new Connection(,22);try conn.connect();conn.authenticateWithPassword(itcc, itcc123);SCPClient ftp = conn.createSCPClient();while(true)Session s=conn.openSession();ByteArr

9、ayOutputStream buffer = new ByteArrayOutputStream();byte bytes = new byte1024;String str=sin.readLine();s.execCommand(str);InputStream stdout = new StreamGobbler(s.getStdout();int count;while (count = stdout.read(bytes) != -1)buffer.write(bytes, 0, count);if(count=1024)System.out.println(new String(bytes);elsebyte bs2=new bytecount;for(int j=0;jcount;j+)bs2j=bytesj;System.out.println(new

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论