1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| public static void recursivDir(FTPClient ftpClient, String tmppath)
{
String path = tmppath;
File _File;
FileInputStream _FileInputStream;
byte[] bytesIn = new byte[1024];
int read;
long transfere;
int pourcentage;
int oldPourcentage;
long size;
try
{
_File = new File(fileDir.getPath() + path);
if(_File.exists())
{
File[] files = _File.listFiles();
for(int i = 0; i < files.length; i++)
{
if(files[i].isDirectory())
{
boolean done = ftpClient.makeDirectory(path+"/" + files[i].getName());
recursivDir(ftpClient, path+"/" + files[i].getName());
}
else
{
_File = new File(fileDir.getPath() + path + "/" + files[i].getName());
_FileInputStream = new FileInputStream(_File);
OutputStream outputStream = ftpClient.storeFileStream(path + "/" + files[i].getName());
read = 0;
transfere = 0;
pourcentage = -1;
oldPourcentage = 0;
size = files[i].length();
while((read = _FileInputStream.read(bytesIn)) != -1)
{
outputStream.write(bytesIn, 0, read);
transfere += read;
pourcentage = (int) (transfere * 100/size);
if(pourcentage != oldPourcentage)
{
oldPourcentage = pourcentage;
}
}
_FileInputStream.close();
outputStream.close();
System.out.println("test 1");
if (!ftpClient.completePendingCommand())
{
System.out.println("Erreur. Le fichier n'a pas été upload.");
}
System.out.println("test 2");
}
}
}
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
} |
Partager