Posted by:jusescn
Posted on:2006-05-12 13:14
想在Ftp上创建文件夹,不知道怎么弄?
下面只实现文件上传,无法上传文件夹????
public class FTPUpload {
private FtpClient ftpClient;
public void connectServer(String server, String user, String password,String path) {
// server:FTP服务器的IP地址;user:登录FTP服务器的用户名
// password:登录FTP服务器的用户名的口令;path:FTP服务器上的路径
try {
ftpClient = new FtpClient();
ftpClient.openServer(server);
ftpClient.login(user, password);
if (path.length() != 0)ftpClient.cd(path);
ftpClient.binary();
} catch (IOException ex) {
System.out.println(ex);
}
}
public void closeConnect() {
try {
ftpClient.closeServer();
} catch (IOException ex) {
System.out.println(ex);
}
}
public void upload(String filename,String filepath) {
try {
TelnetOutputStream os = ftpClient.put(filename);
java.io.File file_in = new java.io.File(filepath);
FileInputStream is = new FileInputStream(file_in);
byte[] bytes = new byte[1024];
int c;
while ((c = is.read(bytes)) != -1) {
os.write(bytes, 0, c);
}
is.close();
os.close();
} catch (IOException ex) {
System.out.println(ex);
}
}
public static void main(String[] args) {
FTPUpload ftp = new FTPUpload();
ftp.connectServer("127.0.0.1", "admin", "1234", "");
ftp.upload("bbb","d:\\Ant");
ftp.closeConnect();
}
}