ftpclient.java

来自「Java的ftp实现 包含客户端和服务器端」· Java 代码 · 共 48 行

JAVA
48
字号
/***  文件传输*  @aurth anyx*///package per.anyx.ftp;import java.net.*;import java.io.*;public class FtpClient{    public static void main(String[] args){	if(args.length != 3){	    System.out.println("Usage: FtpClient host_add host_port src_file");	    System.exit(0);	}	File file = new File(args[2]);	if(!file.exists() || !file.isFile()){	    System.out.println("File \"" + args[2] + "\" does not exist or is not a normal file.");	    System.exit(0);	}	Socket s = null;	FileInputStream in = null;	OutputStream out = null;	try{	    s = new Socket(args[0], Integer.parseInt(args[1]));	    in = new FileInputStream(file);	    out = s.getOutputStream();	    byte[] buffer = new byte[1024*8];	    int len = -1;	    System.out.println("File tansfer statr...");	    while((len=in.read(buffer)) != -1){		out.write(buffer, 0, len);	    }	    System.out.println("File tansfer complete...");	}catch(Exception e){	    System.out.println("Error: " + e.getMessage());	    System.exit(1);	}finally{	    try{		if(in != null) in.close();		if(out != null) out.close();		if(s != null) s.close();	    }catch(Exception e){}	}    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?