国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
一步一步android(6):關(guān)于FtpClient類(lèi)的學(xué)習(xí)

研究了半天,學(xué)習(xí)了sun.net.ftp包中的FtpClient類(lèi),用來(lái)實(shí)現(xiàn)Ftp功能。

首先搭好Ftp的測(cè)試環(huán)境

添加windows組件,安裝IIS中的FTP服務(wù)。


在運(yùn)行中輸入inetmgr,對(duì)默認(rèn)ftp站點(diǎn)點(diǎn)右鍵->屬性進(jìn)行配置,



配置好了之后在運(yùn)行中輸入ftp進(jìn)行鏈接測(cè)試


現(xiàn)在ftp的測(cè)試環(huán)境已經(jīng)搭建成功,接下來(lái)用java編程實(shí)現(xiàn)ftp的訪問(wèn)

簡(jiǎn)單介紹一下sun.net.ftp中的FtpClient類(lèi)

該類(lèi)中有:

openServer方法:用于鏈接ftp,類(lèi)似于在ftp(dos格式下)中輸入open命令。

login方法:用于輸入用戶(hù)及密碼,類(lèi)似于在ftp(dos格式下)中輸入user命令。

sendServer方法:用于向ftp服務(wù)器發(fā)送各種指令。

readServerResponse方法:與sendServer方法合用,用于使服務(wù)器返回消息。

getResponseString方法:獲取服務(wù)器返回的消息。

closeServer方法:中斷服務(wù)器鏈接,類(lèi)似于在ftp(dos格式下)中輸入quit命令。

 

 

下面是demo程序的效果


下面是程序源代碼:

 

/*------------------display ftp demo class begin----------------*/

package com.android.Yao;
import java.applet.Applet;

import java.awt.*;

 

 

public class displayftpdemo extends Applet {

TextField tf = new TextField("",45);
Button button = new Button("Send");
Button button1 = new Button("Exit");
TextArea ta = new TextArea("",10,50);
ftpdemo b=new ftpdemo();


public void init()
{
  
   add(ta);
   add(tf);
   add(button);
   add(button1);

   try
   {
    b.connectServer(b.gethostname(), b.getport(), b.getusername(),b.getuserpwd());
    ta.append(b.ftpClient.getResponseString());
   } catch (Exception e) {

    e.printStackTrace();
   }
}

public boolean action(Event e,Object o)
{
  
   if(e.target instanceof Button)
   {
    if(e.target == button)
    {
     try
     {
      ta.append(b.SendServer(b,tf.getText()+"\r\n"));
     }
     catch (Exception ex)
     {
      ex.printStackTrace();
     }
    }
    else if (e.target == button1)
    {
     try
     {
      b.closeServer();
      ta.append(b.ftpClient.getResponseString());
     }
     catch (Exception ex)
     {
      ex.printStackTrace();
     }
    }
   }
   return true;
}

}

/*------------------display ftp demo class end----------------*/

 

 

/*------------------ftpclient class begin ----------------*/

package com.android.Yao;

import sun.net.ftp.*;

public class ftpdemo {

String hostname = "192.168.0.195";
int portnum = 21;
String username = "anonymous";
String userpwd = "111";
FtpClient ftpClient = new FtpClient();

public String gethostname()
{
   return hostname;
}
public int getport()
{
   return portnum;
}
public String getusername()
{
   return username;
}
public String getuserpwd()
{
   return userpwd;
}


    public boolean connectServer(String ip, int port, String user, String pwd)
    throws Exception
    {
    boolean isSuccess = false;  
    try
    {
       ftpClient.openServer(ip, port);
       ftpClient.login(user, pwd);
       isSuccess = true;
    }
    catch (Exception ex)
    {
       throw new Exception("Connect ftp server error:" + ex.getMessage());  
    }
    return isSuccess;  
    }
   
    public boolean closeServer()
    throws Exception
    {
    boolean isSuccess = false;
    try
    {
       ftpClient.closeServer();
       isSuccess = true;
    }
    catch(Exception ex)
    {
       throw new Exception("DisConnect ftp server error:"+ex.getMessage());
    }
    return isSuccess;
    }

public String getFileList()
    throws Exception
    {

    String FileName="no filelist";
   
    this.connectServer(hostname, portnum, username, userpwd);
    try
    {
      
    }
    catch(Exception ex)
    {
      
       throw new Exception("Get FileList error:"+ex.getMessage());
      
    }
    this.closeServer();
   
   
    return FileName;
    }


public String SendServer(ftpdemo a,String cmd)
throws Exception
{
   String result="error\n";
   try
   {
    a.ftpClient.sendServer(cmd);
    a.ftpClient.readServerResponse();   
    result = ftpClient.getResponseString();   
   }
   catch(Exception ex)
   {
    throw new Exception("Get FileList error:"+ex.getMessage());
   }
   return result;
}
}

/*------------------ftpclient class end ----------------*/

 

 

今天一天的學(xué)習(xí)結(jié)束,明天研究研究各個(gè)ftp的指令,以及如何將其整合到Android手機(jī)中!


本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
FTPClient 用法
Java讀取FTP上的txt文件
Java常用FTP文件操作說(shuō)明 Apache.FTPClient,ftp4j,jftp
C# 利用FluentFTP實(shí)現(xiàn)FTP文件上傳下載功能
Android FTP服務(wù)器上傳 Android FTP服務(wù)器上傳文件攻略(代碼詳解)
Android端與Android端利用WIFI進(jìn)行FTP通信
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服