Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: in FTP check if folder exist, if not create the file. without using FTPClient Class only URL`S Class

  1. #1
    Member
    Join Date
    Sep 2019
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default in FTP check if folder exist, if not create the file. without using FTPClient Class only URL`S Class

    this is part of my code.

    * folder name - folder on my ftp server already exist

     
    			URL url3 = new URL("ftp://username:pass@host+folder name" + imageName + ".jpg");
    			URLConnection con3 = url3.openConnection();
    			ObjectOutputStream out3 = new ObjectOutputStream(con3.getOutputStream());
    			ImageIO.write(image, "jpg", out3);
    			out3.flush();
    			out3.close();
    			//end #6

    i have for each client, serial.
    i want to check for client that try to connected to ftp if foldernamed on is serial exist if not (first connection) to create the folder.

    i know thats can be done with FTPClient, but i think its not so hard without FTPClient (because i already read and write files).
    i just dont know how.

    please give very simple solution

    edit: another question, i try to delete file from my drive with file.delete() not working...
    and i can delete file from ftp without FTPClient ? thank you
    Last edited by doronbachar; October 26th, 2019 at 08:45 PM. Reason: i solve it

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: in FTP check if folder exist, if not create the file. without using FTPClient Class only URL`S Class

    Do you have a FTP server with debug mode that will write to a log showing what it does when it receives a request?

    Is there a forum for asking questions about using FTP?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2019
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: in FTP check if folder exist, if not create the file. without using FTPClient Class only URL`S Class

    i use free hosting, i dont think they have log (or i just dont know).
    any way FTPClient work, but if have way not to use this i want to know.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: in FTP check if folder exist, if not create the file. without using FTPClient Class only URL`S Class

    It would help debug the code if there was a log from the server that showed what was wrong.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Sep 2019
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: in FTP check if folder exist, if not create the file. without using FTPClient Class only URL`S Class

    Quote Originally Posted by Norm View Post
    It would help debug the code if there was a log from the server that showed what was wrong.
    nvm, i do like i said:
    1. import org.apache.commons.net.ftp.FTPClient; 
    2. ftpClient.cwd    a. 250 = exist b. 550 = not exist.
    3. ftpClient.makeDirectory("/folder (exist on my ftp)/" + new folder)

    i just wanted for learning and for not import the "apache-commons-net.jar"
    thank you from trying but i see its lot problem to even try

Similar Threads

  1. check whether the path is file or folder
    By viper_pranish in forum Java Theory & Questions
    Replies: 1
    Last Post: March 19th, 2013, 12:38 PM
  2. create a test class (main method) to start(run) the class in Java
    By curious725 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 1st, 2012, 03:21 AM
  3. Can't create inner class object outside the outer class help needed?
    By Dark knight in forum Java Theory & Questions
    Replies: 2
    Last Post: July 31st, 2012, 02:34 AM
  4. Replies: 3
    Last Post: June 17th, 2012, 06:22 PM
  5. In a class create an array list of elements of another class, help!
    By LadyBelka in forum Collections and Generics
    Replies: 3
    Last Post: May 4th, 2011, 05:00 PM