what could be the reason for a file on mapped network drive not being seen by java?

245 Views Asked by At

My code is:

    File file = new File( "T:\\sub1\\15a12f0103135510.jpg");
        long lastModified = file.lastModified();
        System.out.println( "last modified: " + lastModified);
        System.out.println( "done: " + file.exists());

Last modified returns 0. file.exists returns false. However, I can access and open the file through windows explorer, no problem. Accessing the network share directly doesn't work either (in code). Tried smb - shows errors too. I am the admin user on the machine. What could possibly be the reason? what can I check?

if I do the following:

        URL url = new URL( "file://host/share/sub1/15a12f0103135510.jpg");
        url.openStream();

I get the following error:

java.io.IOException: sun.net.ftp.FtpProtocolException: Welcome message: 501 Proxy unable to contact ftp server

        at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:308)
        at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:400)
        at java.net.URL.openStream(URL.java:1045)
        at apiteest.ApiTest.main(ApiTest.java:24)
Caused by: sun.net.ftp.FtpProtocolException: Welcome message: 501 Proxy unable to contact ftp server

        at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1022)
        at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1005)
        at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:294)
        ... 3 more
        Suppressed: java.net.SocketException: Connection reset
                at java.net.SocketInputStream.read(SocketInputStream.java:210)
                at java.net.SocketInputStream.read(SocketInputStream.java:141)
                at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
                at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
                at sun.net.ftp.impl.FtpClient.readServerResponse(FtpClient.java:420)
                at sun.net.ftp.impl.FtpClient.readReply(FtpClient.java:497)
                at sun.net.ftp.impl.FtpClient.issueCommand(FtpClient.java:539)
                at sun.net.ftp.impl.FtpClient.close(FtpClient.java:1131)
                at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:303)
                ... 3 more
Exception in thread "main" java.io.IOException: sun.net.ftp.FtpProtocolException: Welcome message: 501 Proxy unable to c
ontact ftp server

Update: the code works when executed from powershell but not when executed from powershell started as administrator (the same user though). it also doesn't work from a service, even though the service runs under the same user. Why is it so? And how to enable the share (and possibly the mapped drive) for the service?

0

There are 0 best solutions below