想知道远程Windows PC上文件夹的大小

时间:2015-06-23 07:14:02

标签: java

我想知道远程Windows PC的文件夹大小。我也有远程PC的凭据。

到目前为止,我已经测试了这个程序。我的本地系统工作,但不是远程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" );*/

       }
    }

错误: - java.net.UnknownHostException:\ 199.258.63.85

0 个答案:

没有答案