Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android上的Jsch rm线程同步器_Android_Multithreading_Ssh_Jsch - Fatal编程技术网

android上的Jsch rm线程同步器

android上的Jsch rm线程同步器,android,multithreading,ssh,jsch,Android,Multithreading,Ssh,Jsch,我正在用android开发sftp。我使用JSch在服务器和设备之间建立通道,但我有一个问题: 首先,用户必须选择要下载的文件列表,并为每个文件创建一个intentService来下载该文件。然后我进行md5检查,以了解下载是否正常,最后,如果完整性正常,我必须从服务器上删除该文件 主要问题是我有一个错误:SftpException 4:没有说明,我认为当我尝试从服务器删除文件时,服务已关闭,因此频道已关闭,无法找到文件 我有其他活动监控所有下载+全局进度。但是我不能删除这个文件,因为主线程上的

我正在用android开发sftp。我使用JSch在服务器和设备之间建立通道,但我有一个问题:

首先,用户必须选择要下载的文件列表,并为每个文件创建一个intentService来下载该文件。然后我进行md5检查,以了解下载是否正常,最后,如果完整性正常,我必须从服务器上删除该文件

主要问题是我有一个错误:SftpException 4:没有说明,我认为当我尝试从服务器删除文件时,服务已关闭,因此频道已关闭,无法找到文件

我有其他活动监控所有下载+全局进度。但是我不能删除这个文件,因为主线程上的网络。。。因此,我认为我可以在一个单独的线程上创建SftpChannel并将其提供给活动。但是我该怎么做呢?我知道BroadcastIntents无法发送这些类型的数据

因此,请继续:

DownloadSFTPService=>IntentService:打开SftpChannel并下载文件,将数据发送到RunningDownloadsActivity进行进度

RunningDownloadsActivity => ListActivity : Monitor all the downloads + global receiving via BrodcastIntent updates from DownloadSftpService. 
下载服务:

protected void onHandleIntent(Intent intent) {

    //initializations

    //Création de la session avec le serveur
    JSch jsch = new JSch();
    Session session = null;
    try {
        session = jsch.getSession(loginFtp, ipServer, GlobalEnum.DOWNLOAD.PORT);
        if(session == null)
        {
            Log.e("SSHError","Impossible d'instancier la session");
        }
        else
        {

            //Configuration de la connexion par mot de passe plutot que certificat
            java.util.Properties config = new java.util.Properties();
            config.put("StrictHostKeyChecking", "no");
            config.put("PreferredAuthentifications", "password");
            session.setConfig(config);

            //Récupération du mot de passe dans les préférences et ouverture de session avec le serveur
            session.setPassword(passwordFtp);
            session.connect();

            //Configuration du canal en mode sFTP et ouverture
            Channel channel = session.openChannel("sftp");
            sftpChannel = (ChannelSftp) channel;
            sftpChannel.connect();

            //Initialisation de la notification
            initialiseNotif();

            //Lancement du téléchargement des fichiers
            downloadFiles();

            //Clôture de la connexion
            sftpChannel.disconnect();

        }
    } catch (JSchException e) {
        Log.e("JschException", e.toString());
    } catch (SftpException e) {
        Log.e("SftpException", e.toString());
    }

}

    private void downloadFiles() throws SftpException
{
    Vector<ChannelSftp.LsEntry> file;

    //Pour chaque fichier
    for( String tempFileName : downloadList)
    {           
        if(fileExisting(tempFileName)) {
            //Récupération des infos fichier
            file = sftpChannel.ls(tempFileName);
            currentFileSize = file.get(0).getAttrs().getSize();
            currentFileName = file.get(0).getFilename();

            broadcastIntentRD.putExtra(GlobalEnum.DOWNLOAD.FILE_NAME, currentFileName);
            broadcastIntentRD.putExtra(GlobalEnum.DOWNLOAD.FILE_SIZE, currentFileSize);

            //Lancement du téléchargement 

            int lastDot = tempFileName.lastIndexOf(".");
            String baseFileName = null;
            if(tempFileName.endsWith("tar.gz"))
            {
                String temp = tempFileName.substring(0, lastDot);
                baseFileName = temp.substring(0, temp.lastIndexOf("."));
            } else {
                baseFileName = tempFileName.substring(0, lastDot );
            }

            try {
                sftpChannel.get(baseFileName + ".md5", Environment.getExternalStorageDirectory() + vamsillaPath + "/" + baseFileName + ".md5");
            } catch (SftpException e) {
                Log.v("Sftp", "md5 introuvable pour : " + currentFileName);
            }
            sftpChannel.get(file.get(0).getFilename(), Environment.getExternalStorageDirectory() + vamsillaPath + "/" + file.get(0).getFilename(),this);
        }

    }
请原谅我的英语,我是法国人,你知道我们的外语水平有多高


谢谢

可能已经晚了,但如果它能帮助某人。。。 我最终创建了一个类,继承了Thread doing network+删除文件,当我们停止搜索困难的方法时,它非常简单:

public class DownloadReceiverRD extends BroadcastReceiver{


    @Override
    public void onReceive(Context context, Intent intent) {

        //BLABLA for notification and progressbar update

                    if(progress == fileSize){

                        //BLABLA for notification and progressbar closing


                        md5Sum(fileName);
                    }
                }
      private void md5Sum(String currentFileName) {
        VamsillaTools tools = new VamsillaTools(getApplicationContext());

        //Ouverture de la base de stockage des fichiers

        //Insertion du résultat dans la BDD
        int result = tools.checkMD5(currentFileName);
        db.insertFile(currentFileName, result);
        switch(result) {
            case -1 : Log.v("MD5", "Problème lors de la comparaison md5 : " + currentFileName); break;
            case 0 : Log.v("MD5", "Comparaison md5 fausse : " + currentFileName); break;
            case 1 : Log.v("MD5", "Succès de la comparaison md5 pour : " + currentFileName);

    /********
      SUPRESS THE FILE HERE WOULD BE PERFECT !!! 
    *********/

   break;
        }
    }
}