Android
2014. 2. 16. 21:37
FTP는 MainThread에서는 수행되지 않는다.
별도의 thread나 asynctask를 이용한다
try {
FTPClient mFTP = new FTPClient();
mFTP.connect("123.123.123.123", 21); // ftp로 접속
mFTP.login("ftpuser", "password"); // ftp 로그인 계정/비번
mFTP.setFileType(FTP.BINARY_FILE_TYPE); // 바이너리 파일
mFTP.setBufferSize(1024 * 1024); // 버퍼 사이즈
mFTP.enterLocalPassiveMode(); 패시브 모드로 접속
// 업로드 경로 수정 (선택 사항 )
mFTP.cwd("public"); // ftp 상의 업로드 디렉토리
mFTP.mkd("files"); // public아래로 files 디렉토리를 만든다
mFTP.cwd("files"); // public/files 로 이동 (이 디렉토리로 업로드가 진행)
File path = new File("/sdcard/dcim/camera/"); // 업로드 할 파일이 있는 경로(예제는 sd카드 사진 폴더)
if (path.listFiles().length > 0) { // 폴더를 가지고와 폴더 내부 파일 리스트를 만든다
for (File file : path.listFiles()) {
if (file.isFile()) {
FileInputStream ifile = new FileInputStream(file)
mFTP.rest(file.getName()); // ftp에 해당 파일이있다면 이어쓰기
mFTP.appendFile(file.getName(), ifile); // ftp 해당 파일이 없다면 새로쓰기
}
}
}
mFTP.disconnect(); // ftp disconnect
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
'Android' 카테고리의 다른 글
안드로이드] Fragment 쉽게 사용하기 (15) | 2013.08.22 |
---|---|
안드로이드] 페이스북 같은 슬라이드 메뉴 만들기 (49) | 2013.08.19 |
안드로이드] 쉬운 log 관리 (0) | 2013.07.26 |
안드로이드] Custom ArrayAdapter의 기본 틀 (0) | 2013.07.25 |
안드로이드] SharedPreferences 깔끔하게 사용하기 (9) | 2013.07.09 |