Apache project nets Project-The commons-net-1.2.2.jar function is complete, the example code is as follows:

Source: Internet
Author: User
Tags nets

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 ();
}
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.