List of usage examples for org.apache.commons.net.ftp FTPCmd FEAT
FTPCmd FEAT
To view the source code for org.apache.commons.net.ftp FTPCmd FEAT.
Click Source Link
From source file:com.streamsets.pipeline.stage.origin.remote.FTPAndSSHDUnitTest.java
protected void setupFTPServer(String homeDir) throws Exception { fakeFtpServer = new SessionTrackingFakeFtpServer(); fakeFtpServer.setServerControlPort(0); fakeFtpServer.setSystemName(FTPClientConfig.SYST_UNIX); fakeFtpServer.setFileSystem(new UnixFakeFileSystem()); UserAccount userAccount = new UserAccount(TESTUSER, TESTPASS, homeDir); fakeFtpServer.addUserAccount(userAccount); fakeFtpServer.start();//ww w . j ava 2s. co m port = fakeFtpServer.getServerControlPort(); populateFakeFileSystemFromReal(new File(homeDir)); // Add the missing FEAT and MDTM commands fakeFtpServer.setCommandHandler(FTPCmd.FEAT.getCommand(), new StaticReplyCommandHandler(211, "MDTM")); fakeFtpServer.setCommandHandler(FTPCmd.MDTM.getCommand(), new AbstractStubCommandHandler() { @Override protected void handleCommand(Command command, Session session, InvocationRecord invocationRecord) { String pathname = command.getOptionalString(0); if (!pathname.startsWith("/")) { pathname = homeDir + "/" + pathname; } invocationRecord.set(StatCommandHandler.PATHNAME_KEY, pathname); FileSystemEntry file = fakeFtpServer.getFileSystem().getEntry(pathname); if (file == null) { sendReply(session, 550, null, "No such file or directory.", null); } else { String time = MDTM_DATE_FORMAT.format(file.getLastModified()); sendReply(session, 213, null, time, null); } } }); }
From source file:com.streamsets.pipeline.lib.remote.FTPAndSSHDUnitTest.java
protected void setupFTPSServer(String homeDir, KeyStoreType serverKeystoreType, KeyStoreType clientKeystoreType, boolean implicitSsl) throws Exception { FtpServerFactory serverFactory = new FtpServerFactory(); ListenerFactory factory = new ListenerFactory(); factory.setPort(0);/*from w w w . java2 s.co m*/ if (serverKeystoreType != null) { serverCertificateKeystore = generateCertificateKeystore(serverKeystoreType); if (clientKeystoreType != null) { clientCertificateKeystore = generateCertificateKeystore(clientKeystoreType); } SslConfigurationFactory sslFactory = new SslConfigurationFactory(); sslFactory.setKeystoreFile(serverCertificateKeystore); sslFactory.setKeystorePassword(KEYSTORE_PASSWORD); sslFactory.setClientAuthentication(clientKeystoreType != null ? "yes" : "none"); sslFactory.setTruststoreFile(clientCertificateKeystore); sslFactory.setTruststorePassword(KEYSTORE_PASSWORD); factory.setSslConfiguration(sslFactory.createSslConfiguration()); factory.setImplicitSsl(implicitSsl); } serverFactory.addListener("default", factory.createListener()); PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory(); UserManager um = userManagerFactory.createUserManager(); BaseUser user = new BaseUser(); user.setName(TESTUSER); user.setPassword(TESTPASS); user.setHomeDirectory("/"); user.setAuthorities(Collections.singletonList(new WritePermission())); um.save(user); serverFactory.setUserManager(um); // For whatever reason, they hardcode the root of the filesystem to be the user's home dir. This prevents us from // testing scenarios where userDirIsRoot is false because we can't get out of the user dir. As a workaround, we set // the user's home dir to root (see above) and then modify the FileSystemView to change the working directory to the // user's home dir instead - this properly emulates the expected behavior. FileSystemFactory fsf = new NativeFileSystemFactory() { @Override public FileSystemView createFileSystemView(User user) throws FtpException { FileSystemView view = super.createFileSystemView(user); view.changeWorkingDirectory(homeDir); return view; } }; serverFactory.setFileSystem(fsf); CommandFactoryFactory cff = new CommandFactoryFactory(); // Allow pretending to not support MDTM by overriding the FEAT command to return an empty String (i.e. supports no // extra features) if supportMDTM is false cff.addCommand(FTPCmd.FEAT.getCommand(), new FEAT() { @Override public void execute(FtpIoSession session, FtpServerContext context, FtpRequest request) throws IOException, FtpException { if (supportMDTM) { super.execute(session, context, request); } else { session.resetState(); session.write(new DefaultFtpReply(211, "")); } } }); serverFactory.setCommandFactory(cff.createCommandFactory()); ftpServer = (DefaultFtpServer) serverFactory.createServer(); ftpServer.start(); port = ftpServer.getListener("default").getPort(); }
From source file:com.atomicleopard.thundr.ftp.commons.FTP.java
/** * A convenience method to send the FTP FEAT command to the server, receive the reply, * and return the reply code.// w ww . ja va 2s. c om * @return The reply code received by the server * @throws IOException If an I/O error occurs while either sending the * command or receiving the server reply. * @since 2.2 */ public int feat() throws IOException { return sendCommand(FTPCmd.FEAT); }