日期:2014-05-20 浏览次数:21350 次
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.TimeZone;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
public class RemoteFileUtil {
public void dologin() {
try {
//链接到ftp服务器
ftpClient = new FTPClient();
ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
ftpClient.connect("10.32.65.26",22);
ftpClient.login("root", "xwtech83");
System.out.println("登录成功.");
FTPFile[] remoteFiles = ftpClient.listFiles("/root");
System.out.println("目录" + remoteDir + "下的文件:");
if(remoteFiles != null) {
for(int i=0;i<remoteFiles.length;i++) {
String name = remoteFiles[i].getName();
System.out.println(name + ":\t\t" + name);
}
}
} catch (Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
remoteFile.dologin();
}