0

I want to know the folder size of a remote Windows PC. I have credentials of the remote PC also.

So far I have tested this program. I works on my local system but not remote PC.

package ext.Size;


    import java.io.File;
    import org.apache.commons.io.FileUtils;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;

    import org.apache.commons.net.ftp.FTP;
    import org.apache.commons.net.ftp.FTPClient;

    public class FileSize {
        public static void main(String[] args)
        {
            FileSize fs= new FileSize();
            Float size=fs.ReturnSize("\\\\199.258.63.85\\D:\\test_folder");
            if(size!=07)
            System.out.println(size);

        }
       public static float ReturnSize(String  args) {

           String server = "\\\\199.258.63.85";
           int port = 22;
           String user = "test75";
           String pass = "testpass75";
           System.out.println("server=="+server);


           try {
               FTPClient ftpClient = new FTPClient();
               ftpClient.connect(server,port);
               ftpClient.login(user, pass);
               //ftpClient.enterLocalPassiveMode();
               //ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

               float size = FileUtils.sizeOfDirectory
                          (new File(args));

                          System.out.println("Size: " + size + " bytes" + size/1073741824 + "GB" );
                          return size;
           }
           catch(Exception e)
           {
               System.out.println(e);
               return 07;
           }

          /*float size = FileUtils.sizeOfDirectory
          (new File(args));

          System.out.println("Size: " + size + " bytes" + size/1073741824 + "GB" );*/

       }
    }

Error:- java.net.UnknownHostException: \199.258.63.85

Nikos Paraskevopoulos
  • 39,514
  • 12
  • 85
  • 90
Maninder Singh
  • 135
  • 4
  • 12
  • Can you clarify what network protocol do you want to use in your code. \\\\199.258.63.85 is Windows cifs protocol and org.apache.commons.net.ftp.FTPClient uses FTP protocol, for which you will need running FTP server on Windows box. There is problem with the path \\\\199.258.63.85\\D:\\test_folder, which is messed up. The correct syntax is \\\. If you have shared D:\\test_folder as test_folder on 199.258.63.85, the correct will be \\\\199.258.63.85\\test_folder – Anton Krosnev Jun 23 '15 at 07:35
  • I have tried the \\\\199.258.63.85\\test_folder also test_folder is shared. All i need is a way to get into remote pc using my username and password of remote pc – Maninder Singh Jun 23 '15 at 07:45
  • Getting into the remote PC is not that easy, see for options http://stackoverflow.com/q/208839/3080094 – vanOekel Jun 23 '15 at 12:54
  • @vanOekel Mounting is not an option since network glitch will every time unmount the machine also every time remote pc or local is restarted. Need a permanent working solution. – Maninder Singh Jun 24 '15 at 07:35
  • I am using AWS servers hence its complex since each one is hosted on different blade and accessing thorough program is not allowed – Maninder Singh Jan 08 '17 at 06:59

0 Answers0