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!
- package tema04;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import org.apache.commons.net.ftp.FTP;
- import org.apache.commons.net.ftp.FTPClient;
- public class BajarFichero {
- public static void main(String[] args) {
- FTPClient cliente = new FTPClient(); // Client
- String servidor = "192.168.203.191"; // Servidor
- String user = "alumno";
- String pasw = "alumno";
- try {
- System.out.println("Conectandose a " + servidor);
- cliente.connect(servidor);
- boolean login = cliente.login(user, pasw);
- String direc = "/NUEVODIREC";
- if (login) {
- cliente.changeWorkingDirectory(direc);
- cliente.setFileType(FTP.BINARY_FILE_TYPE);
- // Stream de baixada de l'arxiu
- BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("text2.txt"));
- if(cliente.retrieveFile("text2.txt",out)) {
- System.out.println("Recuperat correctament...");
- }
- else {
- System.out.println("No s'ha pogut descarregar...");
- }
- out.close();
- cliente.logout();
- cliente.disconnect();
- }
- }
- catch( IOException ioe) {
- ioe.printStackTrace();
- }
- }
- }
RAW Paste Data

