You are on page 1of 3

static void FTPuploadfile(String fulllocalpath) {

String pathfile = "";


boolean done;
File LocalFile;
String RemoteFile;String DestMoveFile;

File[] faFiles = new File(fulllocalpath).listFiles();


System.out.println("Test..");
for (File file : faFiles) {
if (file.isDirectory()) {
FTPuploadfile(file.getAbsolutePath());
} else if (file.getName().matches("^(.*?)")) {
System.out.println(file.getAbsolutePath());
try {
// **** Membaca nama folder dan file lokal
pathfile = file.getAbsolutePath();
LocalFile = new File(pathfile);
RemoteFile = LocalFile.getName();
// DestMoveFile = a;
InputStream inputStream = new FileInputStream(LocalFile);
System.out.println("Start uploading first file");
// **** Proses transfer ke FTP Server
done = ftpClient.storeFile(RemoteFile, inputStream);
inputStream.close();
if (done) {
System.out.println("The first file is uploaded successfully.");
} else {
System.out.println("The first file is uploaded gagal.");
}
// **** Close file lokal
// Files.move(LocalFile, DestMoveFile);

} catch (IOException ex) {


System.out.println("Error: " + ex.getMessage());
ex.printStackTrace();
} finally {
//try {
System.out.println("File : " + pathfile + "sukses");
//} catch (IOException ex) {
// ex.printStackTrace();
//}
}
}
}
}

public static void printFnames(String sDir) {


File[] faFiles = new File(sDir).listFiles();
//System.out.println("Test..");
for (File file : faFiles) {
String path1 = file.getAbsolutePath();
String path2 = path1.replace("finish", "finish2");
Path source = Paths.get(path1);
Path target = Paths.get(path2);
if (file.isDirectory()) {
//String path1 = file.getAbsolutePath();
System.out.println("Direktori : " + path1);
try {
Files.createDirectories(target);
} catch (IOException e) {
System.err.println("Failed to create directory!" + e.getMessage());
}
printFnames(file.getAbsolutePath());
} else if (file.getName().matches("^(.*?)")) {
//System.out.println(file.getAbsolutePath());
System.out.println("File : " + path1);
System.out.println("File : " + path2);
try {
Files.move(source, target,StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}

}
}

You might also like