• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Problem with Windows Folders having Spaces

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
My requirement is to transfer files (download/upload) from a remote windows shared drive. I'm using JCIFS API to achieve it. I'm able to connect & download files from there. The issue is when the folder name on the remote machine has spaces, my code is failing with "Failed to connect to server" error.
Below is the code snippet


When executed, I'm getting SMB exception. When tried with folders without spaces, its working absolutely fine. Would you please help me out?

jcifs.smb.SmbException: Failed to connect to server
java.net.UnknownHostException: \\HostIP\Trans-serv\1_NBWCPSUP\Test Files\My Folder-Cycle 1\hi.txt
at jcifs.UniAddress.getAllByName(UniAddress.java:315)
at jcifs.smb.SmbFile.getFirstAddress(SmbFile.java:862)
at jcifs.smb.SmbFile.connect(SmbFile.java:951)
at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
at jcifs.smb.SmbFile.open0(SmbFile.java:972)
at jcifs.smb.SmbFile.open(SmbFile.java:1006)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:73)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:65)
at WinFileTransfer.main(WinFileTransfer.java:37)
 
Rancher
Posts: 1043
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The unescaped blackslashes inside a String literal seem problematic to me, though the file name reported in the error message seems to be correct. Strange.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to put the entire path in quotes (escaped double quotes) to make sure windows keeps the path together as one term instead of splitting it at the spaces.
 
santosh batta
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Steve,
Thanks for your response. I've figured it out. The problem is with the string "smb://". For some reason, its not accepting this as the correct URL format. I've modified it as below

"smb:"+"//"+hostIP+....

and it worked.

The other problem, I forget to address is the File transfer rate. It is taking approximately 2 min. to download 9MB file which I feel is very less. I've tried several ways with changing the buffer size, but it doesn't help significantly. Is there any way to improve the performance?
 
Sheriff
Posts: 22716
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

santosh batta wrote:


Semi unrelated, but that line is wrong. 0 is a valid return value, and it does not indicate you're done. Change it into != -1, > -1 or >= 0.
 
santosh batta
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob,
When I change the condition to >=0 or != -1 , the performance still got worse. Previously it was taking 2 min. to download 9MB file & now its taking 5 min.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

santosh batta wrote:Hi Rob,
When I change the condition to >=0 or != -1 , the performance still got worse. Previously it was taking 2 min. to download 9MB file & now its taking 5 min.



Most likely it was taking 2 min. to download part of a 9MB file, until read() returned 0. Even if you got the whole file that time, the code is wrong and isn't guaranteed to work.

If performance is a problem, you might try wrapping your InputStream in a BufferedInputStream, if you're not already doing so.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic