文件名称:JAVA程序中FTP的连接以及上传文件
文件大小:1KB
文件格式:RAR
更新时间:2013-03-03 07:07:46
FTP java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import sun.net.TelnetOutputStream;
import sun.net.TelnetInputStream;
import sun.net.ftp.FtpClient;
public class ftptest
{
FtpClient ftpClient;
private String localfilename;
private String remotefilename;
static String a = new String();
static int b;
static String c = new String();
static String d = new String();
static String e = new String();
File aFile = new File("e:\\12\\");
String[] fileList = aFile.list();
public void connectServer(String ip, int port,String user, String password,String path)
{
try {
ftpClient = new FtpClient();
ftpClient.openServer(ip,port);
ftpClient.login(user, password);
System.out.println("login success!");
if (path.length() != 0)
{
ftpClient.cd(path);
}
ftpClient.binary();
} catch (IOException ex) {
System.out.println("not login");
System.out.println(ex);
}
}
public void closeConnect()
{
try {
ftpClient.closeServer();
System.out.println("disconnect success");
}
catch (IOException ex)
{
System.out.println("not disconnect");
System.out.println(ex);
}
}
public void upload() {
//this.localfilename = "e://12//bb.txt";
//this.remotefilename = "bb.txt";
for(int i = 0; i
【文件预览】:
ftptest.java