如何递归复制SDcard目录和子目录到其他smb目录(samba)?

时间:2016-08-13 07:46:23

标签: android smb

我正在使用Jcifs库。 我尝试这个代码是工作复制父目录和文件但子目录不复制..

调用函数

for (int j = 0; j < AppConst.checkfilelist.size(); j++) {
                String old = AppConst.checkfilelist.get(j);
                Log.d("smb_c_check_item", "" + AppConst.checkfilelist.get(j));
                copyToDirectory(old, AppConst.destinationpath);

            }

功能

public int copyToDirectory(String old, String newDir) {
        try {
            SmbFile old_file = new SmbFile(old);
            SmbFile temp_dir = new SmbFile(newDir);

            Log.d("smb_c_sour:desti_dir", "" + old + "---" + newDir);

            // copy file
            if (old_file.isFile()) {

                Log.d("smb_c_file","yes");

                String file_name = old.substring(old.lastIndexOf("/"), old.length());
                Log.d("smb_c_file_name", "" + file_name);

                String servername="smb://+ ipaddress+/";


                NtlmPasswordAuthentication auth1 = new NtlmPasswordAuthentication(servername, "", "");

                // smb file path
                SmbFile cp_smbfile = new SmbFile(newDir + file_name.substring(1),auth1);
                Log.d(" smb_c_file_path", "" + cp_smbfile);

                if (!cp_smbfile.exists())
                    cp_smbfile.createNewFile();
                cp_smbfile.connect();

                InputStream in = new FileInputStream(String.valueOf((old_file)));

                SmbFileOutputStream sfos = new SmbFileOutputStream(cp_smbfile);

                byte[] buf = new byte[1024];
                int len;
                while ((len = in.read(buf)) > 0) {
                    sfos.write(buf, 0, len);
                }

                // copy directory
            } else if (old_file.isDirectory()) {

                String servername="smb://+ ipaddress+/";
                NtlmPasswordAuthentication auth1 = new NtlmPasswordAuthentication(servername, "", "");
                Log.d("smb_c_folder","yes");
                String files[] = old_file.list();

                int len = files.length;
                Log.d("smb_c_dirlength", "" + len);

                for(int i1=0;i1<len;i1++){
                    Log.d("smb_c_dir---",""+files[i1]);
                }

                // remove last character
                old = old.substring(0, old.length() - 1);
                // get dir name
                String old_f = old.substring(old.lastIndexOf("/"), old.length());
                Log.d("smb_c_old_f", "" + old_f);

                //create smbfile path
                SmbFile smbdir = new SmbFile(newDir + old_f.substring(1),auth1);


                // create new directory
                if (!smbdir.exists()) {
                    Log.d("smb_c_mkdir", "created");
                    smbdir.mkdirs();
                    //return -1;
                }

                Log.d("smb_c_dir", "" + smbdir);
                for (int i = 0; i < len; i++) {
                    copyToDirectory(old + "/" + files[i], smbdir + "/");
                    Log.d("smb_copy_rec", "" + old + "/" + files[i] + ":" + smbdir + "/");
                }


            } else if (!temp_dir.canWrite())
                Log.d("smb_c_dir_noperm","yes");
                return -1;

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return 0;
    }

Thanx提前提出任何建议或帮助。感谢我的坏人..

1 个答案:

答案 0 :(得分:-1)

我找到了解决方案..

/var/log/nodejs/nodejs.log
-------------------------------------
npm ERR! Linux 4.4.14-24.50.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v4.4.6-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v4.4.6-linux-x64/bin/npm" "start"
npm ERR! node v4.4.6
npm ERR! npm  v2.15.5
npm ERR! code ELIFECYCLE
npm ERR! cidermics@0.0.1 start: `node app.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the cidermics@0.0.1 start script 'node app.js'.
npm ERR! This is most likely a problem with the cidermics package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node app.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs cidermics
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! 
npm ERR!     npm owner ls cidermics
npm ERR! There is likely additional logging output above.
npm ERR! Linux 4.4.14-24.50.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v4.4.6-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v4.4.6-linux-x64/bin/npm" "start"
npm ERR! node v4.4.6
npm ERR! npm  v2.15.5
npm ERR! path npm-debug.log.3664877195
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open

npm ERR! Error: EACCES: permission denied, open 'npm-debug.log.3664877195'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, open 'npm-debug.log.3664877195']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'open',
npm ERR!   path: 'npm-debug.log.3664877195' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /var/app/current/npm-debug.log

> cidermics@0.0.1 start /var/app/current
> node app.js

/var/app/current/node_modules/multer/node_modules/mkdirp/index.js:90
                    throw err0;
                    ^

Error: EACCES: permission denied, mkdir '/var/app/public'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:794:18)
    at sync (/var/app/current/node_modules/multer/node_modules/mkdirp/index.js:71:13)
    at Function.sync (/var/app/current/node_modules/multer/node_modules/mkdirp/index.js:77:24)
    at new DiskStorage (/var/app/current/node_modules/multer/storage/disk.js:21:12)
    at module.exports (/var/app/current/node_modules/multer/storage/disk.js:65:10)
    at new Multer (/var/app/current/node_modules/multer/index.js:15:20)
    at multer (/var/app/current/node_modules/multer/index.js:88:12)
    at Object.<anonymous> (/var/app/current/routes/admin.js:8:14)
    at Module._compile (module.js:409:26)

npm ERR! Linux 4.4.14-24.50.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v4.4.6-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v4.4.6-linux-x64/bin/npm" "start"
npm ERR! node v4.4.6
npm ERR! npm  v2.15.5
npm ERR! code ELIFECYCLE
npm ERR! cidermics@0.0.1 start: `node app.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the cidermics@0.0.1 start script 'node app.js'.
npm ERR! This is most likely a problem with the cidermics package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node app.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs cidermics
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! 
npm ERR!     npm owner ls cidermics
npm ERR! There is likely additional logging output above.
npm ERR! Linux 4.4.14-24.50.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v4.4.6-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v4.4.6-linux-x64/bin/npm" "start"
npm ERR! node v4.4.6
npm ERR! npm  v2.15.5
npm ERR! path npm-debug.log.1654992227
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open

npm ERR! Error: EACCES: permission denied, open 'npm-debug.log.1654992227'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, open 'npm-debug.log.1654992227']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'open',
npm ERR!   path: 'npm-debug.log.1654992227' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /var/app/current/npm-debug.log