How to save a file in another computer within the same network knowing IP address and path

63 Views Asked by At

I have to move a file from a server to another. I can connect to the source serve and retrieve the file via smb, but once I have the file, I can save it on my machine without any problem, but I'm having troubles on copying it to another server. The target server is a Windows machine, I know IP address and the folder where I want to save the file to. Based on the error I'm receiving, I think something is wrong on the target path.

Here's what I'm using:

public static void main(String args[]) throws Exception {
    String from = "smb://IpAddress/.../tmp/";
    String toServer = "//.... what should i write here??";
    String filename = "someFileName.xml";

    moveSmbFileToServer(from, toServer, filename);
} // main   

public static void moveSmbFileToServer (String smbPathFrom, String pathTo, String fileName)  throws Exception {
    SmbFile smbFileFrom = new SmbFile(smbPathFrom + fileName);
    File fileTo = new File(pathTo + fileName);
    InputStream is = null;
    OutputStream os = null;
    try {
        is = smbFileFrom.getInputStream();
        os = new FileOutputStream(fileTo);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = is.read(buffer)) > 0)
            os.write(buffer, 0, length);

//      smbFileFrom.delete(); // commented so I can test multiple times. Will be uncommented once the writing works
    } finally {
        is.close();
        os.close();
    }
    
} // moveSmbFileToServer
0

There are 0 best solutions below