• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

problem while creating multiple directories using mkdir of Jsch

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


I am getting an exception "2 : No such File" while calling mkdir function of ChannelSftp class of Jsch Library.


At the time of calling a function i am passing value "testing/FirstFolder" but it doesn't create a folder inside a folder and gives me an exception.

If I create a single folder then it will be created successfully like For Eg: if i give mkdir("testing"); then it will create "testing" folder on ftp successfully but just after this if I call mkdir("testing"+File.separator+"FirstFolder"); then it gives me an exception of No such file.




Please help me to get out of this problem...

Thanks
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To create the folder "testing/FirstFolder" the folder "testing" must exist. You need to use
BUT - you will get an exception if either of the folders already exists. You can either ignore it if you are sure the file is actually a directory or you can use use the stat() method to look at the attributes.

P.S. I don't actually get a "No such File" exception but I don't have access to your code to see what I am doing differently.
 
Om Prakash Bijawat
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Richard ya its working fine ...actually the prob is of File separator..

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I usually check if the file or folder exists before creating it, else skip the mkdir and do the ftp or copy or whatever with the files.
 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Om Prakash Bijawat wrote:Thanks Richard for you reply...

But this is not working for me...
Here is my code

Jsch jsch =new JSch();

Session session = jsch.getSession(userName,host);

session.setPassword(password);

java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
config.put("PreferredAuthentications", "password");

session.setConfig(config);
session.connect();


Channel channel = session.openChannel("sftp");
ChannelSftp sftp = (ChannelSftp) channel;


sftp.connect();

System.out.println("Pwd : "+sftp.pwd());




But that code does not try to make a directory! And what does not work? What are the symptoms of 'does not work' ? Please please please tell the whole story or I am wasting my time.

Edit: your edit pulled the rug from under my feet!
 
Om Prakash Bijawat
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can we check that whether the file or folder is already exist or not..?
 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Om Prakash Bijawat wrote:How can we check that whether the file or folder is already exist or not..?



You need to look at the Javadoc! There is a method stat() on sftp channel!
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In case you don't know where the API is click here
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Om Prakash Bijawat wrote:actually the prob is of File separator..


Makes sense. File.separator is the file separator on your own machine. It's not necessarily the same as on the remote machine. If you're on a Windows machine it usually isn't.
reply
    Bookmark Topic Watch Topic
  • New Topic