Apache project nets Project-The commons-net-1.2.2.jar function is complete, the example code is as follows:
Import java. Io .*;
Import java.net. inetaddress;
Import org.apache.commons.net. FTP .*;
Import org.apache.commons.net. FTP. parser .*;
Import org.apache.commons.net. FTP. ftpfile;
Import org.apache.commons.net. FTP. ftpfileentryparser;
Import sun.net. telnetinputstream;
Public class ftpappache {
Public ftpappache () throws exception {
// Sun.net. FTP. ftpclient Ft = NULL;
// Telnetinputstream T = ft. List ();
// T. setstickycrlf (true );
}
Public void test1 () throws exception {
//
String strtemp = "";
// Inetaddress IA = inetaddress. getbyname ("192.168.0.193 ");
Ftpclient FTP = new ftpclient ();
FTP. Connect ("192.168.0.193 ");
Boolean blogin = ftp. login ("de"," 123456 ");
If (! Blogin ){
System. Out. println ("connection failed ");
FTP. Disconnect ();
FTP = NULL;
Return;
}
/* // If it is a Chinese name, Character Set conversion is required
Boolean bmakeflag = ftp. makedirectory (new string ("test directory". getbytes (
"Gb2312"), "iso-8859-1"); // create a directory on the server
// Upload files to the server and create directories freely
File file = new file ("C: \ test. properties ");
FTP. storefile ("test. properties", new fileinputstream (File ));*/
System. Out. println (ftp. getsystemname ());
Ftpfile [] ftpfiles = ftp. listfiles ();
If (ftpfiles! = NULL ){
For (INT I = 0; I <ftpfiles. length; I ++ ){
System. Out. println (ftpfiles [I]. getname ());
// System. Out. println (ftpfiles [I]. isfile ());
If (ftpfiles [I]. isfile ()){
Ftpfile ftpf = new ftpfile ();
/* System. Err. println (ftpf. haspermission (ftpfile. group_access,
Ftpfile. execute_permission ));
System. Err. println ("read_permission =" + ftpf. haspermission (ftpfile. user_access,
Ftpfile. read_permission ));
System. Err. println ("execute_permission =" + ftpf. haspermission (ftpfile. user_access,
Ftpfile. execute_permission ));
System. Err. println ("write_permission =" + ftpf. haspermission (ftpfile. user_access,
Ftpfile. write_permission ));
System. Err. println (ftpf. haspermission (ftpfile. world_access,
Ftpfile. read_permission ));*/
}
// System. Out. println (ftpfiles [I]. getuser ());
}
}
// Download the Server File
Fileoutputstream Fos = new fileoutputstream ("E:/proftpd-1.2.10.tar.gz ");
FTP. retrievefile ("proftpd-1.2.10.tar.gz", FOS );
FOS. Close ();
// Change the FTP directory
// Ftp. changetoparentdirectory (); // return to the parent directory
// Ftp. changeworkingdirectory (""); // transfer the working directory
// Ftp. completependingcommand ();//
// Delete the FTP Server File
// Ftp. deletefile ("");
// Deregister the current user,
// Ftp. logout ();
// Ftp. structuremount ("");
FTP. Disconnect ();
FTP = NULL;
}
Public static void main (string [] ARGs ){
Try {
Ftpappache ftpappache1 = new ftpappache ();
Ftpappache1.test1 ();
}
Catch (exception e ){
E. printstacktrace ();
}
}
}