728x90
반응형

//NetComponents-1.3.8 (http://www.savarese.org/downloads/NetComponents/)  라이브러리 필요

import java.io.IOException;
import java.io.PrintWriter;

import com.oroinc.net.ftp.FTP;
import com.oroinc.net.ftp.FTPClient;
import com.oroinc.net.ftp.FTPConnectionClosedException;
import com.oroinc.net.ftp.FTPReply;

public class FtpManager {

    protected static FTPClient ftp;

    protected static boolean FTPConnect(String server, String username, String password){
        ftp = new FTPClient();
        ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

        try {
              int reply;
              ftp.connect(server);
              System.out.println("Connected to " + server + ".");

              // After connection attempt, you should check the reply code to verify
              // success.
              reply = ftp.getReplyCode();

              if(!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                System.out.println("FTP server refused connection.");
                return false;
              }

            //Login FTP
            if(!ftp.login(username, password)) {
                ftp.logout();
                return false;
            }

            System.out.println("Remote system is " + ftp.getSystemName());

            //Setting BINARY method
            ftp.setFileType(FTP.BINARY_FILE_TYPE);

        }catch(FTPConnectionClosedException e) {
            System.out.println("Server closed connection.");
            e.printStackTrace();
            return false;
        } catch(IOException e) {
            if(ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch(IOException f) {
                    //do nothing
                }
            }
            System.out.println("Could not connect to server.");
            e.printStackTrace();
            return false;
        }

        return true;
    }

    protected static boolean FTPConnect(String server, int port, String username, String password){
        ftp = new FTPClient();
        ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

        try {
              int reply;
              ftp.connect(server, port);
              System.out.println("Connected to " + server + ":" + port);

              // After connection attempt, you should check the reply code to verify
              // success.
              reply = ftp.getReplyCode();

              if(!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                System.out.println("FTP server refused connection.");
                return false;
              }

            //Login FTP
            if(!ftp.login(username, password)) {
                ftp.logout();
                return false;
            }

            System.out.println("Remote system is " + ftp.getSystemName());

            //Setting BINARY method
            ftp.setFileType(FTP.BINARY_FILE_TYPE);

        }catch(FTPConnectionClosedException e) {
            System.out.println("Server closed connection.");
            e.printStackTrace();
            return false;
        } catch(IOException e) {
            if(ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch(IOException f) {
                    //do nothing
                }
            }
            System.out.println("Could not connect to server.");
            e.printStackTrace();
            return false;
        }

        return true;
    }


    public static void FTPDisconnect(){
        if(ftp.isConnected()) {
            try {
                ftp.disconnect();
                System.out.println("Disconnect to server.");
            } catch(IOException f) {
                // do nothing
                System.out.println("Disconnect Error. : " + f.getMessage());
                f.printStackTrace();
            }
        }
    }

}
728x90
반응형
728x90
반응형


solaris는 기본 ftp/telnet package가 설치되어있다.

초기 설치시 root user는 보안상 ftp/telnet이 막혀있다.

일반 user는 상관 없단다...ㅡ.ㅡ;;;

root을 이용해서 ftp/telnet을 사용하여야 한다면,

#vi /etc/ftpd/ftpusers -> 파일을 open하셔서 'root'부분을 주석처리

#vi /etc/default/login -> 파일을 open하셔서 "CONSOLE'부분을 주석처리

728x90
반응형

+ Recent posts