① create client
FTPClient ftpClient= new FTPClient();
② client connections landing ftp server
ftpClient.connect (hostname, port); // ftp server connection
ftpClient.login (username, password); // Log in ftp server
③ determine whether the successful landing
int replyCode = ftpClient.getReplyCode (); // replyCode represents the status code is returned.
FTPReply.isPositiveCompletion (replyCode) // status determination status code, if true, indicates that the connection is successful.
④ after the connection operation
A, ftpClient upload files
ftpClient.setFileType (ftpClient.BINARY_FILE_TYPE) // output in binary form
ftpClient.makeDirectory (pathname) after // ftp download file save path
ftpClient.changeWorkingDirectory (pathname) // Switch to the file path
ftpClient.storeFile (fileName, inputStream) // start the download, inputStream represents the data source.
Two: ftpClient download file
ftpClient.changeWorkingDirectory (pathname); // into the working directory
ftpClient.retrieveFile (file.getName (), os); // need to download the file name names, os is BufferReader data origins.
Three: ftpClient delete files
ftpClient.changeWorkingDirectory(pathname);
ftpClient.dele (filename); // delete the corresponding files
⑤ close the connection
ftpClient.loginout ();
ftpClient.disconnected();