import java.io.*;
import com.oroinc.net.ftp.*;
import com.oroinc.net.*;

public class MyFtpClient
{

private static final String sServer = "XXXXXXX"; 서버 아이피
private static final int iPort = 21;
private static final String sId = "XXXXX"; 사용자 아이디
private static final String sPassword = "XXXX"; 비밀번호

private static final String sUpDir = "D:/업무/이성호/laredoute_dev/FTP/upload";
private static final String sDownDir = "D:/업무/이성호/laredoute_dev/FTP/download";
private static final String sLogDir = "D:/업무/이성호/laredoute_dev/FTP/log";

FTPClient ftpClient;
private static Log log; // 이놈은 로그 찍을때 사용

public MyFtpClient()
{
ftpClient = new FTPClient();
log = new Log(sLogDir, "ftp");
}

// 서버로 연결
protected void connect()
{
try
{
ftpClient.connect(sServer, iPort);
int reply;
// 연결 시도후, 성공했는지 응답 코드 확인
reply = ftpClient.getReplyCode();

if(!FTPReply.isPositiveCompletion(reply))
{
ftpClient.disconnect();
log.write("서버로부터 연결을 거부당했습니다");
}

}
catch (IOException ioe)
{
if(ftpClient.isConnected())
{
try
{
ftpClient.disconnect();
}
catch(IOException f)
{
//
}
}
log.write("서버에 연결할 수 없습니다");
}
}

// 계정과 패스워드로 로그인
protected boolean login()
{
try
{
this.connect();
return ftpClient.login(sId, sPassword);
}
catch (IOException ioe)
{
log.write("서버에 로그인 하지 못했습니다");
}
return false;
}

// 서버로부터 로그아웃
protected boolean logout()
{
try
{
return ftpClient.logout();
}
catch (IOException ioe)
{
log.write("로그아웃이 하지 못했습니다");
}
return false;
}

// FTP의 ls 명령, 모든 파일 리스트를 가져온다
protected FTPFile[] list()
{
FTPFile[] files = null;
try
{
files = this.ftpClient.listFiles();
return files;
}
catch (IOException ioe)
{
log.write("서버로부터 파일 리스트를 가져오지 못했습니다");
}
return null;
}

// 파일을 전송 받는다
protected boolean get(String source, String target, String name)
{
boolean flag = false;

OutputStream output = null;
try
{
// 받는 파일 생성 이 위치에 이 이름으로 파일 생성된다
File local = new File(sDownDir, name);
output = new FileOutputStream(local);
}
catch (FileNotFoundException fnfe)
{
log.write("다운로드할 디렉토리가 없습니다");
return flag;
}

File file = new File(source);
try
{
if (ftpClient.retrieveFile(source, output))
{
flag = true;
}
}
catch (IOException ioe)
{
log.write("파일을 다운로드 하지 못했습니다");
}
return flag;
}

// 파일을 전송 받는다 위의 method 와 return 값이 달라서 하나 더 만들었다
protected File getFile(String source, String name)
{
OutputStream output = null;
File local = null;
try
{
// 받는 파일 생성
local = new File(sDownDir, name);
output = new FileOutputStream(local);
}
catch (FileNotFoundException fnfe)
{
log.write("다운로드할 디렉토리가 없습니다");
}

File file = new File(source);
try
{
if (ftpClient.retrieveFile(source, output))
{
//
}
}
catch (IOException ioe)
{
log.write("파일을 다운로드 하지 못했습니다");
}
return local;
}

// 파일을 전송 한다
protected boolean put(String fileName, String targetName)
{
boolean flag = false;
InputStream input = null;
File local = null;

try
{
local = new File(sUpDir, fileName);
input = new FileInputStream(local);
}
catch(FileNotFoundException e)
{
return flag;
}

try
{

// targetName 으로 파일이 올라간다
if(ftpClient.storeFile(targetName, input))
{
flag = true;
}
}
catch(IOException e)
{
log.write("파일을 전송하지 못했습니다");
return flag;
}
return flag;
}

// 서버 디렉토리 이동
protected void cd(String path)
{
try
{
ftpClient.changeWorkingDirectory(path);
}
catch (IOException ioe)
{
log.write("폴더를 이동하지 못했습니다");
}
}

// 서버로부터 연결을 닫는다
protected void disconnect()
{
try
{
ftpClient.disconnect();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}

protected void setFileType(int iFileType)
{
try
{
ftpClient.setFileType(iFileType);
}
catch(Exception e)
{
log.write("파일 타입을 설정하지 못했습니다");
}
}
}

try
{
int port = 443;
String hostname = "hostname";
SocketFactory socketFactory = SSLSocketFactory.getDefault();
Socket socket = socketFactory.createSocket(hostname, port);

// Create streams to securely send and receive data to the server
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();

// Read from in and write to out...

// Close the socket
in.close();
out.close();
}
catch(IOException e)
{
}

class CharTest
{
// 한글인가?
public static boolean isHangul(char c)
{
return isHangulSyllables(c) || isHangulJamo(c) || isHangulCompatibilityJamo(c);
}

// 완성된 한글인가? 참조: http://www.unicode.org/charts/PDF/UAC00.pdf
public static boolean isHangulSyllables(char c)
{
// return (c >= (char) 0xAC00 && c <= (char) 0xD7AF);
return (c >= (char) 0xAC00 && c <= (char) 0xD7A3);
}

// (현대 및 고어) 한글 자모? 참조: http://www.unicode.org/charts/PDF/U1100.pdf
public static boolean isHangulJamo(char c)
{
// return (c >= (char) 0x1100 && c <= (char) 0x11FF);
return (c >= (char) 0x1100 && c <= (char) 0x1159)
|| (c >= (char) 0x1161 && c <= (char) 0x11A2)
|| (c >= (char) 0x11A8 && c <= (char) 0x11F9);
}

// (현대 및 고어) 한글 자모? 참조: http://www.unicode.org/charts/PDF/U3130.pdf
public static boolean isHangulCompatibilityJamo(char c)
{
// return (c >= (char) 0x3130 && c <= (char) 0x318F);
return (c >= (char) 0x3131 && c <= (char) 0x318E);
}

public static void main(String[] args)
{
System.out.println('가' < '각');
String str = "자바클루는 JavaClue다. ㄱ은 한글이다.";
char c;
for (int i = 0; i < str.length(); i++)
{
c = str.charAt(i);
System.out.println("'" + c + "': " + isHangul(c));
}
}
}


출처 http://www.okjsp.pe.kr/bbs?act=VIEW&seq=33317&bbs=bbs4&keyfield=content&keyword=&pg=7

+ Recent posts