블로그 이미지
박공명

카테고리

분류 전체보기 (99)
된장 (7)
Dev (60)
꼐..꼐임 (6)
식탐 (18)
우리 (0)
Etc (8)
개인자료 (0)
Total
Today
Yesterday

ftp upload

Dev/Java / 2010. 3. 24. 18:12


import sun.net.ftp.FtpClient;
import java.io.FileOutputStream;
import sun.net.TelnetOutputStream;
import java.io.IOException;
import sun.net.TelnetInputStream;
import java.io.FileInputStream;
import java.util.zip.*;
import java.util.*;
import java.io.*;

 public boolean doUpLoad(String mode,String s_server,String userid,String passwd) {
  FtpClient ftpClient = new FtpClient();
  TelnetOutputStream os =null ;
  FileInputStream is = null;
  try {
   
   System.out.println("doUpload in");
   ftpClient.openServer(s_server);
   System.out.println("server open");
   ftpClient.login(userid, passwd);
   System.out.println("server login");
   if (serverPath.length() != 0)
    ftpClient.cd(serverPath);
   //System.out.println("-4");
   if("asc".equals(mode)) 
    ftpClient.ascii();
   else
    ftpClient.binary();
   //System.out.println("-5");
   if("".equals(serverFile)) {
    serverFile =  localFile ;
   }
   System.out.println("write file path = " + serverPath+"/"+serverFile);
   os = ftpClient.put(serverPath +"/"+ serverFile );
   System.out.println("read file path = " + localPath+"/"+localFile);
   File file_in = new File(localPath+"/"+localFile);
   is = new FileInputStream(file_in);
   byte[] bytes = new byte[1024];
   int c;
   while ((c = is.read(bytes)) != -1) {
    os.write(bytes, 0, c);
   }
   System.out.println("doUpload complete");
   
   is.close();
   os.close();
   ftpClient.closeServer();
   System.out.println("doUpload close server");
   return true;
  }catch (IOException ie) {
   ie.printStackTrace();
   System.out.println("FTP Exeception -----" + ie.getMessage());
   return false;
  }catch(Exception e){
   e.printStackTrace();
   System.out.println("FTP Exeception -----" + e.getMessage());
   return false;
  }finally{
   try{
    is.close();
    os.close();
    ftpClient.closeServer();
   }catch(Exception e){} 
  }
 }


ㅇㅇㅇ

file.delete(); 만 추가하면 upload 가 아니구 move가 되겠지

'Dev > Java' 카테고리의 다른 글

java.sql.SQLException: 스트림이 이미 종료되었습니다  (0) 2010.03.25
Full GC  (0) 2010.03.25
ftp 파일삭제.  (0) 2010.03.24
정규표현식을 사용하여 스크립트 제거  (1) 2010.03.24
이미지 리사이징 , image resize  (0) 2010.03.24
Posted by 박공명
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함