이 기사의 예는 Java의 FTP 브레이크 포인트 구현 방법을 알려줍니다. 참조를 위해 모든 사람을 위해 공유하십시오. 특정 분석은 다음과 같습니다.
여기서 우리는 주로 Apache에서 Net 패키지를 사용합니다. url http://commons.apache.org/net/. 특정 패키지의 다운로드 및 API 문서는 공식 웹 사이트를 참조하십시오. 중단 점의 업로드는 업로드 중에 전송의 시작 위치를 설정하는 것입니다. 이진 전송을 설정합니다.
java.file java.io.InputStream; .commons.net.printcommandlistener; class wonderftp {private ftpclient ftpclient = new ftpclient (); 콘솔에 대한 명령 출력 this.ftpclient.addprotocolcommandlistener (new PrintCommandListener (system.out));} /*** Java 프로그래밍은 FTP에 연결하는 데 사용됩니다. Server* @param hostname host* @param port port* @param username 사용자 이름* @param password password* @return의 연결이 성공적이든* @throws ioexception*/ public boolen connect (문자열 호스트 이름, int port, string username, String Password)는 ioexception {ftpclien t.connect (hostname, port); false;} / *** ftp 서버에서 파일을 다운로드하십시오* @param 원격 파일 경로* @param 로컬 파일 경로* @return은 성공합니다* @throws ioexception* / public boolen download (string remote, string local). ioexception (); out.println (원격 파일은 고유하지 않습니다. "로컬 파일 크기는"+f.length ()); ". 결과;}/*** 파일 업로드 파일 업로드 FTP 서버로 이동하여 브레이크 포인트를 지원* @param 로컬 로컬 파일 이름, 절대 경로* @param 원격 파일 경로, /home/directory1/subdirectory/file.ext 사양을 사용하십시오. Linux의 경로는 다중 레벨 디렉토리를 지원하여 전례없는 디렉토리 구조의 재귀 제작을 지원합니다.* @Throws ioException*/public uploadstatus upload (String local, string remote)는 ioexception {// set p. AssiveMode ftpclient.EnterLocalPassiveMode (); {remotefilename = remote.substring (remote.lastindexof ( "/")+1); 디렉토리) {// 원격 디렉토리가 존재하지 않으면 원격 서버 디렉토리를 생성합니다. int end = 0; ;} end = indexof ( "/", 시작) {true) {string subdirectory = remote.substring (! ftpclient.changeworkingdirectory)) {if (ftpclient.makedirectory (subdirectory)). {ftpclient.ChangeWorkingDirectory (subdirectory) {system.out.println ( "Create Directory failure"); 모든 디렉토리는 (end <= start) {break;}}}이면 생성됩니다. // ftpfile [] files = ftpclient.listfiles (remotefilename)가 있는지 확인하십시오 [0] getSize (); .rmote_bigger_local;} // inputStream의 중단 점을 달성하기 위해 모바일 파일의 포인터를 읽으려고합니다. ftpclient.storefile (replay, is)) {return upload_from_success (return upload_success) {return uploadstatus.delete_remote_fail; .upload_new_new _file_success;} else {result = uploadstatus.upload_new_file_faled;} is.close ();} else {inputStream is = new FileInputStream (local); lse {result = uploadstatus.upload_new_file_faird;} is.close ();} return result;} / ** * 원격 서버와 연결을 끊기 위해 연결 * @throws ioexception * / public void disconnect () ioexception {if (ftpclient.isconnect ()) {ftpclient.disconnect ()} public static void main (string [] args) {new wonderftp () {myftp.connect, flv ","/mis/video/vp6 .flv "); myftp.disconnect ();} catch (ioexception e) {system.out.println ("ftp 오류 연결 : "+e.getMessage ());}}}이 기사는 모든 사람의 Java 프로그램 설계에 도움이되기를 바랍니다.