daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 29th, 2018 57 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.FileInputStream;
  5. import java.io.IOException;
  6.  
  7. import org.apache.commons.net.ftp.FTP;
  8. import org.apache.commons.net.ftp.FTPClient;
  9.  
  10. public class SubirFichero {
  11.  
  12.     public static void main(String[] args) {
  13.        
  14.         FTPClient cliente = new FTPClient(); // Client
  15.         String servidor = "ftp.dlptest.com"; // Servidor
  16.         String user = "dlpuser@dlptest.com";
  17.         String pasw = "hZ3Xr8alJPl8TtE";
  18.        
  19.         try {
  20.             System.out.println("Conectandose a " + servidor);
  21.             cliente.connect(servidor);
  22.             boolean login = cliente.login(user, pasw);
  23.             String direc = "/NUEVODIREC";
  24.             if (login) {
  25.                 cliente.changeWorkingDirectory(direc);
  26.                 cliente.setFileType(FTP.BINARY_FILE_TYPE);
  27.                
  28.                 // Stream de entrada con el fichero a subir
  29.                 BufferedInputStream in = new BufferedInputStream(new FileInputStream("text.txt"));
  30.                 cliente.storeFile("text.txt",in);
  31.                
  32.                 // Stream d'entrada amb el fitxer a pujar
  33.                 in = new BufferedInputStream(new FileInputStream("cosa.jpg"));
  34.                 cliente.storeFile("cosa.jpg",in);
  35.                
  36.                 in.close();
  37.                 cliente.logout();
  38.                 cliente.disconnect();
  39.             }
  40.         }
  41.         catch( IOException ioe) {
  42.             ioe.printStackTrace();
  43.         }
  44.  
  45.     }
  46.  
  47. }
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top