List of usage examples for org.apache.commons.net.ftp FTPClient printWorkingDirectory
public String printWorkingDirectory() throws IOException
From source file:CFDI_Verification.CFDI_Verification.java
public static String test_Connection(String directory) { String server = "192.1.1.64"; String user = "ftpuser"; String pass = "Oracle123"; String result = "No Connected!"; FTPClient ftpClient = new FTPClient(); try {//from w ww .ja v a2 s. c o m ftpClient.connect(server); ftpClient.login(user, pass); ftpClient.enterLocalPassiveMode(); ftpClient.changeWorkingDirectory(directory); if (ftpClient.isConnected() == true) { result = "Connected to " + ftpClient.printWorkingDirectory(); } ftpClient.logout(); ftpClient.disconnect(); } catch (IOException ex) { System.out.println("Ooops! Error en conexin." + ex.getMessage()); } finally { return result; } }
From source file:com.jaspersoft.jasperserver.api.engine.common.util.impl.FTPUtil.java
private static void changeDirectory(FTPClient ftpClient, String directoryPath) throws Exception { if (ftpClient == null) throw new JSException("Please connect to FTP server first before changing directory!"); if (log.isDebugEnabled()) log.debug("Original Working directory = " + ftpClient.printWorkingDirectory()); ftpClient.changeWorkingDirectory(directoryPath); if (log.isDebugEnabled()) log.debug("NEW Working directory = " + ftpClient.printWorkingDirectory()); }
From source file:com.jaspersoft.jasperserver.api.engine.common.util.impl.FTPUtil.java
private static boolean exists(FTPClient ftpClient, String fileName) throws Exception { if (ftpClient == null) throw new JSException("Please connect to FTP server first before changing directory!"); try {//from w w w . j ava 2 s . co m if (log.isDebugEnabled()) log.debug("FTP Working directory = " + ftpClient.printWorkingDirectory()); FTPFile[] files = ftpClient.listFiles(ftpClient.printWorkingDirectory()); if (log.isDebugEnabled()) log.debug("FTP: number of files - " + (files == null ? "NULL" : files.length)); if (files == null) return false; for (FTPFile ftpFile : files) { if (ftpFile.getName().equalsIgnoreCase(fileName)) return true; } return false; } catch (Exception ex) { ex.printStackTrace(); return false; } }
From source file:com.jaspersoft.jasperserver.api.engine.common.util.impl.FTPUtil.java
private static void putFile(FTPClient ftpClient, String fileName, InputStream inputData) throws Exception { if (ftpClient == null) throw new JSException("Please connect to FTP server first before changing directory!"); if (log.isDebugEnabled()) log.debug("START: FUT FILE = " + fileName); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); boolean state = ftpClient.storeFile(ftpClient.printWorkingDirectory() + "/" + fileName, inputData); if (log.isDebugEnabled()) log.debug("END: FUT FILE = " + fileName + " STATE = " + state); if (!state) { throw new JSException("Fail to upload file " + fileName); }/* w w w. j ava 2 s .c om*/ }
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:com.taurus.compratae.appservice.impl.EnvioArchivoFTPServiceImpl.java
public void conectarFTP(Archivo archivo) { FTPClient client = new FTPClient(); /*String sFTP = "127.0.0.1"; String sUser = "tae";//w w w . j av a2 s .c o m String sPassword = "tae";*/ String sFTP = buscarParametros(FTP_SERVER); String sUser = buscarParametros(FTP_USER); String sPassword = buscarParametros(FTP_PASSWORD); /////////////////////////////////// //String[] lista; try { client.connect(sFTP); boolean login = client.login(sUser, sPassword); System.out.println("1. Directorio de trabajo: " + client.printWorkingDirectory()); client.setFileType(FTP.BINARY_FILE_TYPE); BufferedInputStream buffIn = null; buffIn = new BufferedInputStream(new FileInputStream(archivo.getNombre())); client.enterLocalPassiveMode(); StringTokenizer tokens = new StringTokenizer(archivo.getNombre(), "/");//Para separar el nombre de la ruta. int i = 0; String nombre = ""; while (tokens.hasMoreTokens()) { if (i == 1) { nombre = tokens.nextToken(); i++; } else { i++; } } client.storeFile(nombre, buffIn); buffIn.close(); /*lista = client.listNames(); for (String lista1 : lista) { System.out.println(lista1); }*/ //client.changeWorkingDirectory("\\done"); //System.out.println("2. Working Directory: " + client.printWorkingDirectory()); client.logout(); client.disconnect(); System.out.println("Termin de conectarme al FTP!!"); } catch (IOException ioe) { ioe.printStackTrace(); } }
From source file:com.claim.support.FtpUtil.java
public void uploadMutiFileWithFTP(String targetDirectory, FileTransferController fileTransferController) { try {// w ww .jav a 2 s.c o m FtpProperties properties = new ResourcesProperties().loadFTPProperties(); FTPClient ftp = new FTPClient(); ftp.connect(properties.getFtp_server()); if (!ftp.login(properties.getFtp_username(), properties.getFtp_password())) { ftp.logout(); } int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); } ftp.enterLocalPassiveMode(); System.out.println("Remote system is " + ftp.getSystemName()); ftp.changeWorkingDirectory(targetDirectory); System.out.println("Current directory is " + ftp.printWorkingDirectory()); FTPFile[] ftpFiles = ftp.listFiles(); if (ftpFiles != null && ftpFiles.length > 0) { for (FTPFile file : ftpFiles) { if (!file.isFile()) { continue; } System.out.println("File is " + file.getName()); OutputStream output; output = new FileOutputStream( properties.getFtp_remote_directory() + File.separator + file.getName()); ftp.retrieveFile(file.getName(), output); output.close(); } } ftp.logout(); ftp.disconnect(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:lucee.runtime.tag.Ftp.java
/** * get url of the working directory/* w w w . j av a 2 s .co m*/ * @return FTPCLient * @throws IOException * @throws PageException */ private FTPClient actionGetCurrentURL() throws PageException, IOException { FTPClient client = getClient(); String pwd = client.printWorkingDirectory(); Struct cfftp = writeCfftp(client); cfftp.setEL("returnValue", "ftp://" + client.getRemoteAddress().getHostName() + pwd); return client; }
From source file:lucee.runtime.tag.Ftp.java
/** * get path from the working directory/*from w ww. ja v a 2 s . c om*/ * @return FTPCLient * @throws IOException * @throws PageException */ private FTPClient actionGetCurrentDir() throws PageException, IOException { FTPClient client = getClient(); String pwd = client.printWorkingDirectory(); Struct cfftp = writeCfftp(client); cfftp.setEL("returnValue", pwd); return client; }
From source file:lucee.runtime.tag.Ftp.java
private boolean existsDir(FTPClient client, String strPath) throws PageException, IOException { strPath = strPath.trim();//from w w w. j a v a 2 s. c o m // get parent path FTPPath path = new FTPPath(client.printWorkingDirectory(), strPath); String p = path.getPath(); String n = path.getName(); strPath = p + "" + n; if ("//".equals(p)) strPath = "/" + n; if (!strPath.endsWith("/")) strPath += "/"; String pwd = client.printWorkingDirectory(); boolean rc = client.changeWorkingDirectory(directory); client.changeWorkingDirectory(pwd); return rc; }