FTP

package com.lhw.ftp;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.StringTokenizer;
import sun.net.TelnetOutputStream;
import sun.net.ftp.FtpClient;
/**
* FTP文件配置远程连接
*/
public class FtpClientUtil {
String localfilename;
String remotefilename;
FtpClient ftpClient;
public FtpClientUtil() {
ftpClient = new FtpClient();
}
/***************************************************************************
* 判断指定ftp服务器是否能够连接,并且指定目录
* @param ip
* @param port
* @param user
* @param password
* @param path
* @throws IOException
*/
public void connectServer(String ip, int port, String user,
String password, String path) throws IOException {
ftpClient.openServer(ip, port);
ftpClient.login(user, password);
System.out.println("login success!");
ftpClient.ascii();
//ftpClient.binary();
}
public void connectServer(String ip, int port, String user, String password)
throws IOException {
ftpClient.openServer(ip, port);
ftpClient.login(user, password);
String currentpath = ftpClient.pwd();
System.out.println(ip + "login success!");
ftpClient.ascii();
//ftpClient.binary();
}
/***************************************************************************
* 指向指定路径,指定文件加,用来放置上传文件,同时制定下载文件的路径, 那么每次上传下载文件,要先做这个操作,指定到某个路径(文件??
*
* @param ftpClient
* @param path
* @throws Exception
*/
public void cdPath(String path) throws Exception {
boolean isexit = false;// 标识文件夹或者文件是否存??
if (path.length() != 0) {
// isexit = isDirExist(path);
// if (isexit == false) {
// createDir(path);
// }
try {
ftpClient.cd(path);
} catch (IOException e) {
throw new Exception(path + ",该路经不存在,或??无权访问该目");
}
}
}
/***************************************************************************
* 用来????ftp服务器能否连接,这里????这么????,我这个直接用ajax来实现,用来
* @param ip
* @param port
* @param user
* @param password
* @return
* @throws IOException
*/
public boolean connectServercheckByIndex(String ip, int port, String user,
String password,String path){
FtpClient ftpCli = new FtpClient();
try {
ftpCli.openServer(ip, port);
ftpCli.login(user, password);
ftpCli.cd(path);
System.out.println("login success!");
} catch (IOException e) {
return false;
} finally {
try {
if (ftpCli.serverIsOpen()) {
ftpCli.closeServer();
System.out.println("disconnect success");
}
} catch (IOException ex) {
System.out.println("not disconnect");
System.out.println(ex);
return false;
}
}
return true;
}

你可能感兴趣的:(C++,c,Ajax,OS,C#)