나는 말도 안되는 말을하지 않을 것입니다. 나는 당신에게 코드를 게시 할 것입니다. 특정 코드는 다음과 같습니다.
// 파일 업로드 public static boolean uploadtoftp (문자열 URL, int 포트, 문자열 사용자 이름, 문자열 암호, 문자열 경로, 문자열 파일 이름, 입력 입력) {boolean success = false; ftpclient ftp = new ftpclient (); // org.apache.commons.net.ftp try {if (port> -1) {ftp.connect (url, port); } else {ftp.connect (url); // ftp의 기본 포트는 21}입니다. // 많은 사람들이 ftp.getReplyCode ()를 사용하여 연결의 반환 값을 얻기 위해 씁니다. 그러나 이로 인해 StoreFilestream이 널 리턴 if (ftp.login (username, password)) {ftp.enerlocalactivemode (); ftp.setfileType (ftpclient.binary_file_type); // 디렉토리를 작성하면 존재하는 경우 ftp.makedirectory (path)를 반환하지 못합니다. // 디렉토리를 전환 ftp.changeworkingDirectory (Path); // 파일 업로드 // ftp 프로토콜은 파일 인코딩 형식이 iso-8859-1 filename = new String (filename.getBytes ( "gbk"), "iso-8859-1")를 규정합니다. outputStream out = ftp.storeFilestream (filename); 바이트 [] 바이트 레이 = 새로운 바이트 [4096]; int read = 0; while ((read = input.read (bytearray))! = -1) {out.write (bytearray, 0, read); } out.close (); ftp.logout (); 성공 = 참; }} catch (예외 e) {} 마지막으로 {if (ftp.isconnected ()) {ftp.disconnecct (); }}} // 파일 파일 다운로드 public static boolean downloadfromftp (문자열 URL, int 포트, 문자열 사용자 이름, 문자열 암호, 문자열 경로) {부울 성공 = false; ftpclient ftp = new ftpclient (); // org.apache.commons.net.ftp try {int reply; if (port> -1) {ftp.connect (url, port); } else {ftp.connect (url); // ftp의 기본 포트는 21}입니다. // 많은 사람들이 ftp.getReplyCode ()를 사용하여 연결의 반환 값을 얻기 위해 씁니다. 그러나 StoreFilestream이 null ftp.login (Username, Password) ftp.enterlocalactivemode ()를 반환하게됩니다. ftp.setfileType (ftpclient.binary_file_type); 답장 = ftp.getReplyCode (); if (! ftpReply.ispositionCompletion (reply)) {ftp.disconnect (); 반환 성공; s} // 디렉토리를 여기에서 스위치, 스위칭에 실패하면 ftp.changeworkingdirectory (path)에 경로가 없음을 의미합니다. // 파일을 업로드 ftpfile [] fs = ftp.listfiles (); outputStream out = null; inputStream in = null; for (int i = 0; i <fs.length; i ++) {ftpfile ff = fs [i]; String outFilename = ff.getName (); // 로컬 파일을 만들 때 인코딩 형식 뒤로 문자열을 변환해야합니다. localfilename = new String (ff.getName (). getBytes ( "iso-8859-"), "gbk"); localfile = 새 파일 (localPath+lcoalfilename); out = new FileOutputStream (localFile); in = ftp.rectrieveFilestream (Outfilename); 바이트 [] 바이트 레이 = 새로운 바이트 [4096]; int read = 0; while ((read = in.read (bytearray))! = -1) {out.write (bytearray, 0, read); } //이 문장은 FTP 스트림의 채널을 여러 번 작동시키고 각 명령이 ftp.completependingCommand ()를 완료하기 위해 기다리려면 매우 중요합니다. out.flush (); out.close (); ftp.logout (); secess = true; } catch (예외 e) {} 마지막으로 {if (ftp.isconnected ()) {ftp.disconnecct (); }}}위는 편집자가 소개하는 FTP 파일 업로드 및 다운로드의 Java 구현입니다. 나는 그것이 당신에게 도움이되기를 바랍니다. 궁금한 점이 있으면 메시지를 남겨 주시면 편집자가 제 시간에 답장을 드리겠습니다. Wulin.com 웹 사이트를 지원해 주셔서 대단히 감사합니다!