2013-04-15 2 views
0

FTP 서버를 사용하여 파일을 업로드하고 다운로드해야하지만 문제가 있습니다. 많은 해결책을 찾았지만 아무 것도 효과가없는 것 같습니다.FTPClient를 사용하여 파일을 업로드하지 못했습니다.

나는 secureftp-test.com을 테스트 FTP 서버로 사용하고 있습니다.

아래 코드는 FTPClient storeFile 메소드를 사용하고있는 곳의 업로드 코드입니다 만 작동하지 않는 것 같습니다.

public static void main(String[] args) { 
    String server = "ftp.secureftp-test.com"; 
    int port = 21; 
    String user = "test"; 
    String pass = "test"; 

    FTPClient ftpClient = new FTPClient(); 
    try { 

     ftpClient.connect(server, port); 
     boolean login = ftpClient.login(user, pass); 
     System.out.println("login " + login); 
     ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE); 
     ftpClient.setFileType(FTP.BINARY_FILE_TYPE); 

     File firstLocalFile = new File("D:/jetty.pdf"); 

     String firstRemoteFile = "myfile.pdf"; 
     InputStream inputStream = new FileInputStream(firstLocalFile); 

     System.out.println("Start uploading first file"); 
     boolean done = ftpClient.storeFile(firstRemoteFile, inputStream); 
     inputStream.close(); 
     if (done) { 
      System.out.println("The first file is uploaded successfully."); 
     } else { 
      System.out.println("upload failed"); 
     } 

    } catch (IOException ex) { 
     System.out.println("Error: " + ex.getMessage()); 
     ex.printStackTrace(); 
    } finally { 
     try { 
      if (ftpClient.isConnected()) { 
       ftpClient.logout(); 
       ftpClient.disconnect(); 
      } 
     } catch (IOException ex) { 
      ex.printStackTrace(); 
     } 
    } 
} 

출력이 "업로드 실패"일 때마다. 나는 내가 어디 잘못되었는지 이해하지 못한다.

답변

0

포트가 잘못되었습니다. 그것은 사용

FTPS via Auth TLS/SSL and implicit FTP over SSL on port 990 

을 또한주의 깊게 사이트를 읽으면, 업로드 을 금지입니다 :

Chilkat이 보안 FTP 클라이언트 기능을 테스트하고자하는 사람을 위해 테스트 계정을 FTPS 제공합니다. ftp.secureftp-test.com에 접속하고 "test"암호로 "test"로 로그인 한 다음 서버에있는 파일을 다운로드 할 수 있습니다. "test"계정은 디렉토리 목록을 검색 할 수도 있습니다. 그러나 서버로 파일을 업로드하는 것이 제한됩니다.

참조 : secureftp-test.com

+0

감사 Shivan이 지적. 글쎄 샘플 업로드 및 다운로드를 수행하기 위해 사용할 수있는 테스트 용 다른 FTP 서버가 있습니까? –

+0

자신의 FTP 서버를 설정할 수 있습니다 (예 : FileZilla FTP 서버 (Windows) 또는 vsFTPd (Linux 기반) – Raptor

관련 문제