List of usage examples for org.apache.commons.net.ftp FTPClient FTPClient
public FTPClient()
From source file:org.mockftpserver.stub.StubFtpServer_MultipleClientsIntegrationTest.java
/** * Perform initialization before each test * @see org.mockftpserver.test.AbstractTest#setUp() */// ww w.j a v a 2s. com protected void setUp() throws Exception { super.setUp(); stubFtpServer = new StubFtpServer(); stubFtpServer.setServerControlPort(PortTestUtil.getFtpServerControlPort()); stubFtpServer.setCommandHandler(CommandNames.PWD, new CustomPwdCommandHandler()); stubFtpServer.start(); ftpClient1 = new FTPClient(); ftpClient2 = new FTPClient(); ftpClient3 = new FTPClient(); ftpClient1.setDefaultTimeout(1000); ftpClient2.setDefaultTimeout(1000); ftpClient3.setDefaultTimeout(1000); }
From source file:org.mockftpserver.stub.StubFtpServer_StartTest.java
/** * Test setting a non-default port number for the StubFtpServer control connection socket. *//*from w w w . j a v a2s. c om*/ public void testCustomServerControlPort() throws Exception { final int SERVER_CONTROL_PORT = 9187; final String DIR = "abc 1234567"; PwdCommandHandler pwd = new PwdCommandHandler(); pwd.setDirectory(DIR); stubFtpServer = new StubFtpServer(); stubFtpServer.setServerControlPort(SERVER_CONTROL_PORT); stubFtpServer.setCommandHandler(CommandNames.PWD, pwd); stubFtpServer.start(); try { FTPClient ftpClient = new FTPClient(); ftpClient.connect(SERVER, SERVER_CONTROL_PORT); assertEquals("pwd", DIR, ftpClient.printWorkingDirectory()); } finally { stubFtpServer.stop(); } }
From source file:org.mousephenotype.dcc.crawler.Downloader.java
private boolean ftpConnect(String username, String password) { boolean returnValue = false; try {// w w w . j a v a2 s . co m client = new FTPClient(); client.connect(hostname); client.login(username, password); int reply = client.getReplyCode(); if (FTPReply.isPositiveCompletion(reply)) { if (client.setFileType(FTPClient.BINARY_FILE_TYPE)) { returnValue = true; } else { logger.error("Failed to set ftp transfer mode to binary for '{}'... will now close connection", hostname); client.disconnect(); } } else { logger.error("Server at '{}' refused connection", hostname); client.disconnect(); } } catch (IOException e) { logger.error(e.getMessage()); } return returnValue; }
From source file:org.mousephenotype.dcc.crawler.FtpCrawler.java
private boolean connect(String username, String password) { boolean returnValue = false; try {/*from ww w . j a v a 2 s.c o m*/ logger.debug("Crawler is trying to connect to '{}'", hostname); client = new FTPClient(); client.setConnectTimeout(CONNECT_TIMEOUT_MILLISECS); client.connect(hostname); client.login(username, password); int reply = client.getReplyCode(); if (FTPReply.isPositiveCompletion(reply)) { logger.debug("Crawler is connected to ftp server at '{}'", hostname); returnValue = true; } else { logger.error("Server at '{}' refused connection", hostname); client.disconnect(); } } catch (IOException e) { logger.error(e.getMessage()); } return returnValue; }
From source file:org.mousephenotype.dcc.utils.net.ftp.FTPUtils.java
public FTPUtils(String hostname, int port, String username, String password, fileTypes fileType, fileTransferModes fileTransferMode) throws IOException { ///*from w w w . java 2s . co m*/ this.ftpClient = new FTPClient(); // this.ftpClient.connect(hostname, port); this.login = this.ftpClient.login(username, password); this.ftpClient.setFileType(fileType.ordinal()); this.ftpClient.setFileTransferMode(fileTransferMode.value()); if (!this.login) { this.ftpClient.disconnect(); throw new IOException("invalid login credentials"); } }
From source file:org.mule.modules.FtpUtils.java
public static FTPClient createSession(FtpLiteConnectorConfig config, String userName, String hostName, String port, String password) { FTPClient ftp = new FTPClient(); ftp.setControlEncoding(config.getEncoding()); try {//from w ww . j a v a 2 s. c o m ftp.connect(hostName, Integer.parseInt(port)); ftp.login(userName, password); } catch (NumberFormatException e) { throw new FtpLiteHostException("Port was incorrect and could not be parsed"); } catch (SocketException e) { throw new FtpLiteHostException("Error connecting. " + e.toString()); } catch (IOException e) { throw new FtpLiteHostException("Error connecting. " + e.toString()); } return ftp; }
From source file:org.mule.transport.ftp.FtpConnectionFactory.java
public Object makeObject() throws Exception { FTPClient client = new FTPClient(); if (uri.getPort() > 0) { client.connect(uri.getHost(), uri.getPort()); } else {/* w ww . j a v a 2 s .co m*/ client.connect(uri.getHost()); } if (!FTPReply.isPositiveCompletion(client.getReplyCode())) { throw new IOException("Ftp connect failed: " + client.getReplyCode()); } if (!client.login(uri.getUser(), uri.getPassword())) { throw new IOException("Ftp login failed: " + client.getReplyCode()); } if (!client.setFileType(FTP.BINARY_FILE_TYPE)) { throw new IOException("Ftp error. Couldn't set BINARY transfer type: " + client.getReplyCode()); } return client; }
From source file:org.mule.transport.ftp.server.FTPTestClient.java
public FTPTestClient(String server, int port, String user, String password) { super();//from ww w .jav a2 s.co m this.server = server; this.port = port; this.user = user; this.password = password; ftpClient = new FTPClient(); }
From source file:org.mule.transport.ftp.server.FTPTestClient.java
/** * Initiate a connection to the ftp server * @throws IOException//from w w w. j a va 2 s . c o m */ protected void connect() throws IOException { if (!ftpClient.isConnected()) { ftpClient = new FTPClient(); ftpClient.setDefaultTimeout(TIMEOUT); ftpClient.connect(server, port); ftpClient.login(user, password); } }
From source file:org.mule.transport.ftp.server.ServerTest.java
/** * Sanity test that the embedded ftp server is working. Useful as a first step if * the ftp transport tests are failing.//from ww w. ja v a 2s . c om * * @throws Exception */ @Test public void testServerLogin() throws Exception { FTPClient ftpClient = new FTPClient(); ftpClient.connect("localhost", dynamicPort.getNumber()); ftpClient.login("admin", "admin"); }