List of usage examples for org.apache.commons.net.ftp FTPClient quit
public int quit() throws IOException
From source file:lucee.runtime.net.ftp.FTPPoolImpl.java
/** * disconnect a client//from w w w.j av a 2 s . c o m * @param client */ private void disconnect(FTPClient client) { try { if (client != null && client.isConnected()) { client.quit(); client.disconnect(); } } catch (IOException ioe) { } }
From source file:com.alexkasko.netty.ftp.FtpServerTest.java
@Test public void test() throws IOException, InterruptedException { final DefaultCommandExecutionTemplate defaultCommandExecutionTemplate = new DefaultCommandExecutionTemplate( new ConsoleReceiver()); EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override//from w ww .j av a 2 s . c o m protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipe = ch.pipeline(); pipe.addLast("decoder", new CrlfStringDecoder()); pipe.addLast("handler", new FtpServerHandler(defaultCommandExecutionTemplate)); } }); b.localAddress(2121).bind(); FTPClient client = new FTPClient(); // https://issues.apache.org/jira/browse/NET-493 client.setBufferSize(0); client.connect("127.0.0.1", 2121); assertEquals(230, client.user("anonymous")); // active assertTrue(client.setFileType(FTP.BINARY_FILE_TYPE)); assertEquals("/", client.printWorkingDirectory()); assertTrue(client.changeWorkingDirectory("/foo")); assertEquals("/foo", client.printWorkingDirectory()); assertTrue(client.listFiles("/foo").length == 0); assertTrue(client.storeFile("bar", new ByteArrayInputStream("content".getBytes()))); assertTrue(client.rename("bar", "baz")); // assertTrue(client.deleteFile("baz")); // passive assertTrue(client.setFileType(FTP.BINARY_FILE_TYPE)); client.enterLocalPassiveMode(); assertEquals("/foo", client.printWorkingDirectory()); assertTrue(client.changeWorkingDirectory("/foo")); assertEquals("/foo", client.printWorkingDirectory()); //TODO make a virtual filesystem that would work with directory //assertTrue(client.listFiles("/foo").length==1); assertTrue(client.storeFile("bar", new ByteArrayInputStream("content".getBytes()))); assertTrue(client.rename("bar", "baz")); // client.deleteFile("baz"); assertEquals(221, client.quit()); try { client.noop(); fail("Should throw exception"); } catch (IOException e) { //expected; } }
From source file:org.apache.activemq.blob.FTPBlobDownloadStrategy.java
public InputStream getInputStream(ActiveMQBlobMessage message) throws IOException, JMSException { url = message.getURL();/* w w w . ja v a 2s . c om*/ final FTPClient ftp = createFTP(); String path = url.getPath(); String workingDir = path.substring(0, path.lastIndexOf("/")); String file = path.substring(path.lastIndexOf("/") + 1); ftp.changeWorkingDirectory(workingDir); ftp.setFileType(FTPClient.BINARY_FILE_TYPE); InputStream input = new FilterInputStream(ftp.retrieveFileStream(file)) { public void close() throws IOException { in.close(); ftp.quit(); ftp.disconnect(); } }; return input; }
From source file:org.apache.activemq.blob.FTPBlobDownloadStrategy.java
public void deleteFile(ActiveMQBlobMessage message) throws IOException, JMSException { url = message.getURL();/*from w ww . ja v a 2s . c o m*/ final FTPClient ftp = createFTP(); String path = url.getPath(); try { if (!ftp.deleteFile(path)) { throw new JMSException("Delete file failed: " + ftp.getReplyString()); } } finally { ftp.quit(); ftp.disconnect(); } }
From source file:org.apache.activemq.blob.FTPBlobUploadStrategy.java
@Override public URL uploadStream(ActiveMQBlobMessage message, InputStream in) throws JMSException, IOException { FTPClient ftp = createFTP(); try {/* w w w.jav a 2 s . c om*/ String path = url.getPath(); String workingDir = path.substring(0, path.lastIndexOf("/")); String filename = message.getMessageId().toString().replaceAll(":", "_"); ftp.setFileType(FTPClient.BINARY_FILE_TYPE); String url; if (!ftp.changeWorkingDirectory(workingDir)) { url = this.url.toString().replaceFirst(this.url.getPath(), "") + "/"; } else { url = this.url.toString(); } if (!ftp.storeFile(filename, in)) { throw new JMSException("FTP store failed: " + ftp.getReplyString()); } return new URL(url + filename); } finally { ftp.quit(); ftp.disconnect(); } }
From source file:org.apache.activemq.blob.FTPStrategy.java
protected FTPClient createFTP() throws IOException, JMSException { String connectUrl = url.getHost(); setUserInformation(url.getUserInfo()); int port = url.getPort() < 1 ? 21 : url.getPort(); FTPClient ftp = new FTPClient(); try {/*www . j a v a 2 s. co m*/ ftp.connect(connectUrl, port); } catch (ConnectException e) { throw new JMSException("Problem connecting the FTP-server"); } if (!ftp.login(ftpUser, ftpPass)) { ftp.quit(); ftp.disconnect(); throw new JMSException("Cant Authentificate to FTP-Server"); } return ftp; }