List of usage examples for org.apache.commons.net.ftp FTPClient logout
public boolean logout() throws IOException
From source file:TrabajoFinalJava.FormularioVerFicheros.java
public void run() { //************************INICIO****INTERFAZ************************************************************************** JFrame principal = new JFrame("GESTOR DESCARGAS"); //Colores// w w w . j av a2 s .c o m Color nuevoColor = new Color(167, 220, 231); principal.getContentPane().setBackground(nuevoColor); JLabel tituloPrincipal = new JLabel("GESTOR DESCARGAS"); JLabel tituloVentana = new JLabel("VER FICHEROS"); JTextArea cajaFicheros = new JTextArea(12, 20); JButton mostrar = new JButton("MOSTRAR FICHEROS"); JButton atras = new JButton("ATRAS"); JButton salir = new JButton("SALIR"); cajaFicheros.setEditable(false); //Recojo la fuente que se esta utilizando actualmente. Font auxFont = tituloPrincipal.getFont(); //Aplico la fuente actual, y al final le doy el tamao del texto... tituloPrincipal.setFont(new Font(auxFont.getFontName(), auxFont.getStyle(), 30)); tituloVentana.setFont(new Font(auxFont.getFontName(), auxFont.getStyle(), 30)); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); //Asignamos la constante EXIT_ON_CLOSE, cierra la ventana al pulsar la X. principal.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Asignamos al JFrame el Layout que usaremos, GridBagLayout principal.setLayout(gridbag); //aadir botones al layout gbc.gridx = 1; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weighty = 0.1; gbc.fill = GridBagConstraints.HORIZONTAL; principal.add(tituloPrincipal, gbc); gbc.gridx = 1; gbc.gridy = 1; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weighty = 0.1; gbc.fill = GridBagConstraints.NONE; principal.add(tituloVentana, gbc); gbc.gridx = 0; gbc.gridy = 1; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weighty = 0.1; gbc.fill = GridBagConstraints.HORIZONTAL; principal.add(new JScrollPane(cajaFicheros), gbc); gbc.gridx = 1; gbc.gridy = 3; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weighty = 0.1; gbc.fill = GridBagConstraints.NONE; principal.add(mostrar, gbc); gbc.gridx = 0; gbc.gridy = 4; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weighty = 0.1; gbc.fill = GridBagConstraints.NONE; principal.add(atras, gbc); gbc.gridx = 1; gbc.gridy = 4; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weighty = 0.1; gbc.fill = GridBagConstraints.NONE; principal.add(salir, gbc); //cajaFicheros.setEditable(false); //Hace visible el panel principal.setVisible(true); principal.setSize(650, 350); principal.setLocationRelativeTo(null); principal.setResizable(false); //principal.pack(); mostrar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String ftpSsrver = "127.0.0.1"; String ftpUser = "solera"; String ftpPass = "solera"; FTPClient cFtp = new FTPClient(); try { cFtp.connect(ftpSsrver); boolean login = cFtp.login(ftpUser, ftpPass); System.out.print("conexion ftp para ver ficheros establecida"); cFtp.enterLocalPassiveMode(); String[] archivos = cFtp.listNames(); FTPFile[] detalles = cFtp.listFiles(); archivos = cFtp.listNames(); for (int i = 0; i < archivos.length; i++) { /* cajaFicheros.selectAll(); cajaFicheros.replaceSelection(""); */ arrayArchivos.add(archivos[i].toString()); System.out.println(arrayArchivos.get(i)); cajaFicheros.append(System.getProperty("line.separator")); cajaFicheros.append(arrayArchivos.get(i)); } cFtp.logout(); cFtp.disconnect(); System.out.println("Conexion Finalizada, buenas tardes."); } catch (IOException ioe) { System.out.println("error" + ioe.toString()); } } }); try { salir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); } catch (Exception e) { } try { atras.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FormularioAccesoFtp accesoFtp = new FormularioAccesoFtp(); accesoFtp.inicioFtp(); principal.setVisible(false); } }); } catch (Exception e) { } }
From source file:TrabajoFinalJava.subirFicheros.java
@Override public void run() { // Creando nuestro objeto ClienteFTP FTPClient client = new FTPClient(); // Datos para conectar al servidor FTP String ftpServer = "127.0.0.1"; String userFtp = "solera"; String ftpPass = "solera"; try {/*from w ww. j a v a 2 s.co m*/ // Conactando al servidor client.connect(ftpServer); // Logueado un usuario (true = pudo conectarse, false = no pudo // conectarse) boolean login = client.login(userFtp, ftpPass); //client.setFileType(ftpServer.BINARY_FILE_TYPE, FTP.BINARY_FILE_TYPE); // client.setFileTransferMode(ftpServer.BINARY_FILE_TYPE); client.enterLocalPassiveMode(); String filename = "miarchivo.txt"; FileInputStream fis = new FileInputStream(filename); // Guardando el archivo en el servidor client.storeFile(filename, fis); // Cerrando sesin client.logout(); // Desconectandose con el servidor client.disconnect(); } catch (IOException ioe) { System.out.println(ioe.getMessage()); } }
From source file:tufts.oki.dr.fedora.DR.java
public osid.shared.Id ingest(String fileName, String templateFileName, String fileType, File file, Properties properties) throws osid.dr.DigitalRepositoryException, java.net.SocketException, java.io.IOException, osid.shared.SharedException, javax.xml.rpc.ServiceException { long sTime = System.currentTimeMillis(); if (DEBUG)/* w w w. ja v a 2s .com*/ System.out .println("INGESTING FILE TO FEDORA:fileName =" + fileName + "fileType =" + fileType + "t = 0"); // this part transfers file to a ftp server. this is required since the content management part of fedora server needs object to be on web server String host = FedoraUtils.getFedoraProperty(this, "admin.ftp.address"); String url = FedoraUtils.getFedoraProperty(this, "admin.ftp.url"); int port = Integer.parseInt(FedoraUtils.getFedoraProperty(this, "admin.ftp.port")); String userName = FedoraUtils.getFedoraProperty(this, "admin.ftp.username"); String password = FedoraUtils.getFedoraProperty(this, "admin.ftp.password"); String directory = FedoraUtils.getFedoraProperty(this, "admin.ftp.directory"); FTPClient client = new FTPClient(); client.connect(host, port); client.login(userName, password); client.changeWorkingDirectory(directory); client.setFileType(FTP.BINARY_FILE_TYPE); client.storeFile(fileName, new FileInputStream(file.getAbsolutePath().replaceAll("%20", " "))); client.logout(); client.disconnect(); if (DEBUG) System.out.println( "INGESTING FILE TO FEDORA: Writting to FTP Server:" + (System.currentTimeMillis() - sTime)); fileName = url + fileName; // this part does the creation of METSFile int BUFFER_SIZE = 10240; StringBuffer sb = new StringBuffer(); String s = new String(); BufferedInputStream fis = new BufferedInputStream( new FileInputStream(new File(getResource(templateFileName).getFile().replaceAll("%20", " ")))); //FileInputStream fis = new FileInputStream(new File(templateFileName)); //DataInputStream in = new DataInputStream(fis); byte[] buf = new byte[BUFFER_SIZE]; int ch; int len; while ((len = fis.read(buf)) > 0) { s = s + new String(buf); } fis.close(); if (DEBUG) System.out.println("INGESTING FILE TO FEDORA: Read Mets File:" + (System.currentTimeMillis() - sTime)); //in.close(); // s = sb.toString(); //String r = s.replaceAll("%file.location%", fileName).trim(); String r = updateMetadata(s, fileName, file.getName(), fileType, properties); if (DEBUG) System.out.println( "INGESTING FILE TO FEDORA: Resplaced Metadata:" + (System.currentTimeMillis() - sTime)); //writing the to outputfile File METSfile = File.createTempFile("vueMETSMap", ".xml"); FileOutputStream fos = new FileOutputStream(METSfile); fos.write(r.getBytes()); fos.close(); // AutoIngestor a = new AutoIngestor(address.getHost(), address.getPort(),FedoraUtils.getFedoraProperty(this,"admin.fedora.username"),FedoraUtils.getFedoraProperty(this,"admin.fedora.username")); //THIS WILL NOT WORK IN NEWER VERSION OF FEDORA // String pid = AutoIngestor.ingestAndCommit(new FileInputStream(METSfile),"foxml1.","Test Ingest"); if (DEBUG) System.out.println("INGESTING FILE TO FEDORA: Ingest complete:" + (System.currentTimeMillis() - sTime)); String pid = "Method Not Supported any more"; System.out.println(" METSfile= " + METSfile.getPath() + " PID = " + pid); return new PID(pid); }
From source file:ubicrypt.core.provider.ftp.FTProvider.java
private void close(final FTPClient client) { try {/* w ww .ja va 2 s . c o m*/ client.logout(); } catch (final IOException e1) { } try { client.disconnect(); } catch (final IOException e1) { } }
From source file:ucar.unidata.idv.ui.ImageGenerator.java
/** * Do an FTP put of the given bytes/*from w w w .ja v a 2 s . co m*/ * * @param server server * @param userName user name on server * @param password password on server * @param destination Where to put the bytes * @param bytes The bytes * * @throws Exception On badness */ public static void ftpPut(String server, String userName, String password, String destination, byte[] bytes) throws Exception { FTPClient f = new FTPClient(); f.connect(server); f.login(userName, password); f.setFileType(FTP.BINARY_FILE_TYPE); f.enterLocalPassiveMode(); checkFtp(f, "Connecting to ftp server"); f.storeFile(destination, new ByteArrayInputStream(bytes)); checkFtp(f, "Storing file"); f.logout(); f.disconnect(); }
From source file:uk.ac.bbsrc.tgac.miso.core.util.TransmissionUtils.java
public static boolean ftpPut(FTPClient ftp, String path, List<File> files, boolean autoLogout, boolean autoMkdir) throws IOException { boolean error = false; FileInputStream fis = null;//from w w w . ja v a 2s.c o m try { if (ftp == null || !ftp.isConnected()) { error = true; throw new IOException( "FTP client isn't connected. Please supply a client that has connected to the host."); } if (path != null) { if (autoMkdir) { if (!ftp.makeDirectory(path)) { error = true; throw new IOException("Cannot create desired path on the server."); } } if (!ftp.changeWorkingDirectory(path)) { error = true; throw new IOException("Desired path does not exist on the server"); } } log.info("All OK - transmitting " + files.size() + " file(s)"); for (File f : files) { fis = new FileInputStream(f); if (!ftp.storeFile(f.getName(), fis)) { error = true; log.error("Error storing file: " + f.getName()); } boolean success = FTPReply.isPositiveCompletion(ftp.getReplyCode()); if (!success) { error = true; log.error("Error storing file: " + f.getName() + " (" + success + ")"); } } if (autoLogout) { ftp.logout(); } } catch (IOException e) { error = true; log.error("ftp", e); } finally { try { if (fis != null) { fis.close(); } if (autoLogout) { if (ftp != null && ftp.isConnected()) { ftp.disconnect(); } } } catch (IOException ioe) { log.error("ftp", ioe); } } // return inverse error boolean, just to make downstream conditionals easier return !error; }
From source file:uk.ac.bbsrc.tgac.miso.core.util.TransmissionUtils.java
public static boolean ftpPutListen(FTPClient ftp, String path, File file, boolean autoLogout, boolean autoMkdir, CopyStreamListener listener) throws IOException { boolean error = false; FileInputStream fis = null;//from w w w . j av a2s.c o m log.info("ftpPutListen has been called for file:" + file.getName()); try { if (ftp == null || !ftp.isConnected()) { error = true; throw new IOException( "FTP client isn't connected. Please supply a client that has connected to the host."); } if (path != null) { if (autoMkdir) { if (!ftp.makeDirectory(path)) { error = true; throw new IOException("Cannot create desired path on the server."); } } log.info("Working dir =" + ftp.printWorkingDirectory()); if (!ftp.changeWorkingDirectory(path)) { error = true; throw new IOException("Desired path does not exist on the server"); } } fis = new FileInputStream(file); OutputStream ops = new BufferedOutputStream(ftp.storeFileStream(file.getName()), ftp.getBufferSize()); log.info("TransmissionUtils putListen: FTP server responded: " + ftp.getReplyString()); copyStream(fis, ops, ftp.getBufferSize(), file.length(), listener); ops.close(); fis.close(); log.info("TransmissionUtils putListen: FTP server responded: " + ftp.getReplyString()); if (autoLogout) { ftp.logout(); } } catch (IOException e) { error = true; log.error("ftp put listen", e); } finally { try { log.info("TransmissionUtils putListen:finally: " + ftp.getReplyString()); if (fis != null) { fis.close(); } if (autoLogout) { if (ftp != null && ftp.isConnected()) { ftp.disconnect(); } } } catch (IOException ioe) { log.error("ftp put listen close", ioe); } } // return inverse error boolean, just to make downstream conditionals easier log.info("result of transmissionutils.putListen:", !error); return !error; }
From source file:uk.ac.manchester.cs.datadesc.validator.utils.UrlReader.java
private void login(FTPClient ftp) throws VoidValidatorException { try {//from w w w . j av a2s . c o m if (!ftp.login(username, password)) { ftp.logout(); } logger.debug("Remote system is " + ftp.getSystemType()); } catch (IOException ex) { disconnect(ftp); throw new VoidValidatorException( "Unable to log into FTP " + uri + " using username:" + username + " password:" + password); } }
From source file:view.GenerujTest.java
private void sendfile() { FTPClient client = new FTPClient(); FileInputStream fis = null;/*from ww w . j a va 2 s . c o m*/ try { client.connect("ftp.serwer1749827.home.pl"); client.login("serwer", "serwer123456"); // // Create an InputStream of the file to be uploaded // client.removeDirectory("index.html"); String filename = "index.html"; fis = new FileInputStream(filename); // // Store file to server // client.storeFile(filename, fis); client.logout(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fis != null) { fis.close(); } client.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:vv.main.java
private void btnBackupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBackupActionPerformed // TODO add your handling code here: Conectar con = new Conectar(); String nombreCarpeta = "FTF_" + con.getTime("dd-MM-yyyy") + "_" + con.getTime("HHmm"); con.createDir("c:\\tmp\\" + nombreCarpeta); FTPClient client = new FTPClient(); String sFTP = con.IP_FTP;/*from w w w .jav a2s .c om*/ String sUser = con.USUARIO_FTP; String sPassword = con.PASSWORD_FTP; txtLog.setText("INICIO: " + con.getTime("dd-MM-yyyy HH:mm:ss")); try { client.connect(sFTP); boolean login = client.login(sUser, sPassword); con.copiarDir(client, nombreCarpeta); client.logout(); client.disconnect(); } catch (Exception e) { System.out.println("Error:" + e); } txtLog.setText(txtLog.getText() + "\nFIN: " + con.getTime("dd-MM-yyyy HH:mm:ss")); }