ftptest.java

来自「java中ftp连接实例程序」· Java 代码 · 共 57 行

JAVA
57
字号
import java.io.*;
import sun.net.ftp.*;
import sun.net.*;

public class FtpTest{
	public static void main(String args[]){
		FtpClient fc=new FtpClient();
		try{
			fc.openServer("127.0.0.1",8888);
		}catch(IOException ioe){
			System.out.println(ioe);
			}
		System.out.println(fc.getResponseString());
		
		try{
//			fc.binary();
			fc.login("movie","movie");
			System.out.println(fc.getResponseString());
			fc.cd("打印");		
		}catch(IOException ioe){
			System.out.println(ioe);
			}

		InputStream tis=null;
		InputStream gettis=null;
		try{
			
			tis=(InputStream)fc.list();
			gettis=(InputStream)fc.get("说明.txt");
		}catch(IOException ioe){
			System.out.println(ioe);
			}
		
		BufferedReader brIn=new BufferedReader(new InputStreamReader(tis));
		BufferedReader brGetIn=new BufferedReader(new InputStreamReader(gettis));
		String line,getline;
		
		try{
			while((line=brIn.readLine())!=null){
				System.out.println(line);
				}
			}catch(IOException ioe){
				System.out.println(ioe);
				}
		System.out.println("\n now getting......\n说明.txt:");
		try{
			while((getline=brGetIn.readLine())!=null){
				System.out.print(getline);
				}
			}catch(IOException ioe){
				System.out.println(ioe);
				}
		try{
			fc.closeServer();
			}catch(Exception i){}
		}
	}

⌨️ 快捷键说明

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