Hey
I have a FTP server with this
And I have something like
anotherfolder:
afolderinsidethatone:
file1.bin
file2.bin
file.txt
I want to pass all of that to the ftp server so it takes this form:
ftp://192.168.100.2/folder/anotherfolder/
ftp://192.168.100.2/folder/anotherfolder/afolderinsidethatone/
ftp://192.168.100.2/folder/anotherfolder/afolderinsidethatone/file1.bin
ftp://192.168.100.2/folder/anotherfolder/afolderinsidethatone/file2.bin
ftp://192.168.100.2/folder/anotherfolder/file.txt
I have this code:
public void subidaftp(String ip, String usuario, String pass, String fichero, String directorio)
{
FTPClient client = new FTPClient();
FileInputStream fis = null;
try
{
client.connect(ip);
client.login(usuario, pass);
String filename = fichero;
fis = new FileInputStream(filename);
boolean existe=client.changeWorkingDirectory(directorio);
if (existe==false)
{
client.makeDirectory(directorio);
client.storeFile(filename, fis);
client.rename(filename, directorio + filename);
}
else
{
client.storeFile(filename, fis);
client.rename(filename, directorio + filename);
}
client.logout();
}
catch (IOException e)
{
System.out.println("ERROR: Ha ocurrido un error ( " +e.getLocalizedMessage()+" )");
}
finally
{
try
{
if (fis!=null)
{
fis.close();
}
client.disconnect();
}
catch (IOException e)
{
System.out.println("ERROR: Ha ocurrido un error al cerrar el fichero ( " +e.getLocalizedMessage()+" )");
}
}
}
And when I call it, there is no error message (so it finds the file I try to load) but It just creates a empty folder, nothing else.
How can I adapt it to just naming a folder and putting everything in the server keeping the structure?
Thanks