用于通过ftps连接alfresco的Java代码

时间:2014-08-21 11:07:09

标签: java ftp alfresco

嗨我试图通过FTP连接我们的露天但是我得到错误Unknownhostexception

我的代码正在关注

public void FTPTest()throws SocketException, IOException
{

    FTPClient ftp = new FTPClient();
    System.out.println("1");
      ftp.connect("172.17.178.144:2121"); // or "localhost" in your case
      System.out.println("2");
      System.out.println("login: "+ftp.login("admin", "admin"));
      System.out.println("3");
      ftp.changeWorkingDirectory("folder/subfolder/");
      // list the files of the current directory
      FTPFile[] files = ftp.listFiles();  
      System.out.println("Listed "+files.length+" files.");
      for(FTPFile file : files) {
       System.out.println(file.getName());
      }
       // lets pretend there is a JPEG image in the present folder that we want to copy to the desktop (on a windows machine)
      ftp.setFileType(FTPClient.BINARY_FILE_TYPE); // don't forget to change to binary mode! or you will have a scrambled image!
            FileOutputStream br = new FileOutputStream("C:\\Documents and Settings\\casonkl\\Desktop\\my_downloaded_image_new_name.jpg");

      ftp.retrieveFile("name_of_image_on_server.jpg", br);
      ftp.disconnect();

     }

我收到了以下错误

  

java.net.UnknownHostException:172.17.178.144:212 1

1 个答案:

答案 0 :(得分:1)

您应该尝试这样做,将端口设置为单独的参数。

FTPClient ftp = new FTPClient();
ftp.connect("172.17.178.144","2121");
ftpClient.connect(server, port);