List of usage examples for org.apache.commons.net.ftp FTPClient user
public int user(String username) throws IOException
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/*w w w . ja v 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:jsfml1.NewJFrame.java
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed try {//w w w . j av a 2s . c o m // TODO add your handling code here: File f = new File(date + ".html"); FileWriter fw = new FileWriter(f); fw.write("<!--" + date + " " + ose + " " + username + " is good ! -->"); fw.write("<head>"); fw.write("<style>"); fw.write("body {"); fw.write("background: #121212;"); fw.write("color: white;"); fw.write("text-align: center;"); fw.write("}"); fw.write("</style>"); fw.write("<title>Listening on</title>"); fw.write("</head>"); fw.write("<body>"); fw.write("Listening on: <br/><br/>"); fw.write("<audio controls=\"controls\"> <source src=\"" + date + ".wav\"> </audio>"); fw.write("</body>"); fw.close(); JOptionPane jop = new JOptionPane(); jButton4.setText("Uploaded fine !"); FTPClient ftp = new FTPClient(); ftp.connect("ftp.cluster1.easy-hebergement.net", 21); ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.user("toNSite"); ftp.pass("tonMotDePasse"); InputStream is0 = new FileInputStream(date + ".html"); InputStream is = new FileInputStream(date + ".wav"); ftp.storeFile("/uploads/" + date + ".html", is0); ftp.storeFile("/uploads/" + date + ".wav", is); is.close(); Desktop.getDesktop().browse(new URI("http://focaliser.fr/uploads/" + date + ".html")); } catch (MalformedURLException ex) { Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (URISyntaxException ex) { Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.fabric3.transport.ftp.server.host.F3FtpHostTest.java
public void testValidLogin() throws IOException { FTPClient ftpClient = new FTPClient(); ftpClient.connect(InetAddress.getLocalHost(), 1234); ftpClient.user("user"); assertEquals(230, ftpClient.pass("password")); }
From source file:org.fabric3.transport.ftp.server.host.F3FtpHostTest.java
public void testInvalidLogin() throws IOException { FTPClient ftpClient = new FTPClient(); ftpClient.connect(InetAddress.getLocalHost(), 1234); ftpClient.user("user"); assertEquals(530, ftpClient.pass("password1")); }
From source file:org.fabric3.transport.ftp.server.host.F3FtpHostTest.java
public void testStor() throws IOException { FTPClient ftpClient = new FTPClient(); ftpClient.connect(InetAddress.getLocalHost(), 1234); ftpClient.user("user"); ftpClient.pass("password"); ftpClient.enterLocalPassiveMode();/* w w w. jav a 2 s .c om*/ ftpClient.storeFile("/resource/test.dat", new ByteArrayInputStream("TEST\r\n".getBytes())); }