daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 29th, 2018 52 in 29 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package tema04;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.BufferedOutputStream;
  5. import java.io.FileInputStream;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8.  
  9. import org.apache.commons.net.ftp.FTP;
  10. import org.apache.commons.net.ftp.FTPClient;
  11.  
  12. public class BajarFichero {
  13.  
  14.     public static void main(String[] args) {
  15.        
  16.         FTPClient cliente = new FTPClient(); // Client
  17.         String servidor = "192.168.203.191"; // Servidor
  18.         String user = "alumno";
  19.         String pasw = "alumno";
  20.        
  21.         try {
  22.             System.out.println("Conectandose a " + servidor);
  23.             cliente.connect(servidor);
  24.             boolean login = cliente.login(user, pasw);
  25.             String direc = "/NUEVODIREC";
  26.             if (login) {
  27.                 cliente.changeWorkingDirectory(direc);
  28.                 cliente.setFileType(FTP.BINARY_FILE_TYPE);
  29.                
  30.                 // Stream de baixada de l'arxiu
  31.                 BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("text2.txt"));
  32.                 if(cliente.retrieveFile("text2.txt",out)) {
  33.                     System.out.println("Recuperat correctament...");
  34.                 }
  35.                 else {
  36.                     System.out.println("No s'ha pogut descarregar...");
  37.                 }
  38.                                
  39.                 out.close();
  40.                 cliente.logout();
  41.                 cliente.disconnect();
  42.             }
  43.         }
  44.         catch( IOException ioe) {
  45.             ioe.printStackTrace();
  46.         }
  47.  
  48.     }
  49.  
  50. }
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top