I want to upload directory to my FTP server.
This is the code that i use to upload a "single file" to my ftp server, I want to know if there is something that can help me to upload all pictures ".jpg" in this folder "mnt/sdcard/DCIM/Camera" to my FTP.
public static final String TAG = "Contacts";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread t = new Thread(new Runnable(){
@Override
public void run(){
jetzt();
}
});
t.start();
Log.i(TAG, "thread started");
}
public void jetzt(){
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect("HOST SERVER IP");
ftpClient.setSoTimeout(10000);
ftpClient.enterLocalPassiveMode();
if(ftpClient.login(" LOGIN ", " PASSWORD "))
{
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
File sFile=new File("mnt/sdcard/DCIM/Camera/mypicture.jpg");
FileInputStream fs= new FileInputStream(sFile);
String fileName = sFile.getName();
Boolean result = ftpClient.storeFile(fileName, fs);
fs.close();
Log.i(TAG, "sent");
String has = "";
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
You may use this modified function: