2

I am a Mac user, using Java want to copy local folder to a server folder. But I don't see the folder on the server.

package com.ch.chapp.GenericFunctionsLibrary;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

public class copyDir {
    public static void main(String[] args) {
        String source = "/Users/rkan/Documents/workspace/Android-CHAPPAutomationDemo/Report";
        File srcDir = new File(source);

        String destination = "smb://mrblk/MrBlk/AutomationTestReports/CHApp";
        File destDir = new File(destination);

        try {
            FileUtils.copyDirectory(srcDir, destDir);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Robin Green
  • 32,079
  • 16
  • 104
  • 187
  • mount the smb share as a filesystem, then access the folder directly. Are you able to access the folder that way? If so it's just a file reference – Rogue Nov 25 '18 at 08:37

1 Answers1

2

The URL format smb://... is only supported by the Mac desktop environment, and by Linux/Unix desktop environments such as KDE and Gnome, but not by non-desktop-aware software such as the JDK. You need to use the JCIFS library. You can find questions on Stackoverflow about how to use this library, such as this one.

Alternatively, you could mount the smb share using the mount command-line utility, and then access it as a normal filesystem, but AFAIK the initial mount requires sudo access.

Robin Green
  • 32,079
  • 16
  • 104
  • 187