[JSch-users] Re: problem with sftp and lcd'ing to folders that contain space in the name
Status: Alpha
Brought to you by:
ymnk
From: Eric F. <cta...@gm...> - 2005-06-14 16:53:50
|
I was incorrect in my previous statement that "Jsch cannot handle directory names with spaces in them". Rather, the problem I ran into was that the example Sftp.java code was limiting. The example takes user input and places it into a vector called "cmds", which breaks up each part of the command by spaces. Thus, if you have lcd MyFolder then cmds.elementAt(0) would return "lcd" where as cmds.elementAt(1) would return "MyFolder". The example code: if(cmd.equals("cd") || cmd.equals("lcd")){ if(cmds.size()<2) continue; =09String path=3D(String)cmds.elementAt(1); =09=09try{ =09=09//System.out.println("SFTPCLASS: "+path); =09=09=09=09=09=09if(cmd.equals("cd")) c.cd(path); =09=09=09=09=09=09else c.lcd(path); =09=09=09=09=09} =09=09=09=09=09catch(SftpException e){ =09=09=09=09=09=09System.out.println(e.message); =09=09=09=09=09} =09=09=09=09=09continue; =09=09=09=09} =09=09=09=09for(int ii=3D0; ii<i; ii++){ =09=09=09=09=09if(buf[ii]=3D=3D' '){ =09=09=09=09=09=09if(ii-s>0){ cmds.addElement(new String(buf, s, ii-s)); } =09=09=09=09=09=09while(ii<i){if(buf[ii]!=3D' ')break; ii++;} =09=09=09=09=09=09s=3Dii; =09=09=09=09=09} =09=09=09=09} =09=09=09=09if(s<i){ cmds.addElement(new String(buf, s, i-s)); } =09=09=09=09if(cmds.size()=3D=3D0)continue; On 6/13/05, Eric Franz <cta...@gm...> wrote: > Nevermind, I solved my problem. Sorry to bother all! >=20 >=20 > On 6/9/05, Eric Franz <cta...@gm...> wrote: > > To all, > > > > I am trying to automate file transfer in my program, and so to send a > > local file with the absolute path given, I convert it to a series of > > cd .. and lcd "foldername" commands to navigate to the file relative > > to the starting directory, and then send it (much like one would do if > > they were actively using sftp). > > > > The problem is that the Jsch implementation of sftp cannot seem to > > handle directory names with spaces in it. If one runs the sftp > > example provided with the Jsch download, if you try to cd .. back all > > the way to the root directory on a windows machine (C:\) and then > > type: > > lcd "Program Files" > > > > it says "directory doesn't exist" > > > > However, this command does work in other sftp programs. > > > > Am I missing something, or will Jsch not work for my program needs? > > > > Thank you for any help! > > > > ~Eric > > > |