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!
- package tema04;
- import java.io.BufferedInputStream;
- import java.io.FileInputStream;
- import java.io.IOException;
- import org.apache.commons.net.ftp.FTP;
- import org.apache.commons.net.ftp.FTPClient;
- public class SubirFichero {
- public static void main(String[] args) {
- FTPClient cliente = new FTPClient(); // Client
- String servidor = "ftp.dlptest.com"; // Servidor
- String user = "dlpuser@dlptest.com";
- String pasw = "hZ3Xr8alJPl8TtE";
- 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 entrada con el fichero a subir
- BufferedInputStream in = new BufferedInputStream(new FileInputStream("text.txt"));
- cliente.storeFile("text.txt",in);
- // Stream d'entrada amb el fitxer a pujar
- in = new BufferedInputStream(new FileInputStream("cosa.jpg"));
- cliente.storeFile("cosa.jpg",in);
- in.close();
- cliente.logout();
- cliente.disconnect();
- }
- }
- catch( IOException ioe) {
- ioe.printStackTrace();
- }
- }
- }
RAW Paste Data

