• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

FTP Client

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm writing a FTP client and need to check whether or not a directory exists on the FTP server. I know about File.exists() but i'm not too sure how to use it. my code goes like this:
void connect() {
try {
taDisplay.setText("");
String user = tfUserName.getText();
taDisplay.appendText("Connecting to host "+vn);
client = new FtpClient(vn);//added 04/02/2002
client.login(user, pw);
taDisplay.appendText("\nUser "+user+" login OK");
//client.exists();
if (cad.exists()) {
taDisplay.appendText("cad file exists");
}
client.cd(dir);
client.binary();
}
catch (Exception e) {
taDisplay.appendText("\nError1 : "+e.toString());
}
}
i'm getting a null pointer exception and i don't know why.
all my variables have been declared and as far as i can tell all my objects have been instantiated.
Can anyone help?
Pete
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's start with - where are you defining what the variable cad references?
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me just sneak in these two comments (in betwen cindy helping you):
java.io.File:
-- isFile()
-- isDirectory()
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the rest of my code, it's changed a bit since i last posted.
the main problems are in
bClose_actionPerformed()
connect()
putFile()
methods.
i'm having trouble specifying which directory to use and checking whether or not a directory exists.
i'm sorry about the amount of code


edit by Dave to put code in code tags
[ February 08, 2002: Message edited by: Dave Vick ]
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure what ftp api you are using but in the one I use I can have it return to me a listing of all the files and directories on the remote machine just as if I typed "dir" or "ls -la" depending on your remote machine. Then I just have it pull out all the directory names so I know if they exists. I tried using the File class to test on the remote machine but it did not work.
 
Don't touch me. And dont' touch this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic