riahc3 50 Â Team Colleague

It might have been that:

if ((list[i].getType()==FTPFile.DIRECTORY_TYPE) && (list[i].getName().equals(cai)))

line as it now works :)

There is just now one problem :(

I was first told to store everything in C:/ I mean make C:/somefolder, C:/somefolder2, etc but now I have to start in a folder. Work from:

C:/startingfolder/

So Im not sure if change to parent directory changes to C:/ or C:/startingfolder . I am going to have to check that out....

riahc3 50 Â Team Colleague

Before people start flaming me for the title I want to make it perfectly clear that MOST members are very helpful and somewhat polite. They have a lot of knowledge and help out when they can.

My problem is with the posting system. I am registered to nearly 50 forums and I have never encountered one so horrible......

This is more so when posting code. Every forum uses your regular [code][/code] but no, not Daniweb. You have to tab your code. Imagine if Im on a old DOS box and tab isnt supported in the OS (this is a extreme example but just to show) AFAIK, you cant tab on Android/iOS either.

Then there is the "jumping cursor" bug; It makes editing such a pain in the ass that there are posts Ive just said "Forget it" of how annoying it is....

Later this whole "article" change. I still think it is stupid and so do you guys because below this box it says "Contribute New Discussion Thread (Alt+S)". As much as the OpenGraphBlaBla says, you dont see everything using WebGL for example now do you? Linux is more secure than Windows but you still see more Windows users right?

These forums are great its just the system is really messing it up. That being said, lets hear some opinions please :)

riahc3 50 Â Team Colleague

Daniweb has one of the WORST posting systems on the internet currently. Your best bet is to quote it.

riahc3 50 Â Team Colleague

I should explain better than that... Ok, my approach is called Black list approach. What it meant is to reject if the incoming request is not in the list. Your approach is called White list approach which is the opposite -- to accept if the request is in the white list. In many cases, black list approach is unsafe because one may not know all incoming varieties. As a result, some unknown varieties may go through. Yours, on the other hand, will accept if and only if it is a file. It is also safer to add more acceptable conditions to the while list and remains safe; where as, there is no guarantee that it will be safe when add more conditions to rejected list. ;)

OK I guess....

Anyways new code that still does not work :(

This is the same code as before except the switch to ASCII mode is included.

Basically still inserts the the file even if there are more than 44........

Ill comment because I dont feel like translating the variables OVER AND OVER again each time I post new code:

public static void main(String[] args) throws SocketException, IOException 
    {

        int counter=1;
        FTPFile found;
        int done=0;
        FTPClient f=new FTPClient();
        System.out.println("Trying");
        f.connect("192.168.100.2");
        f.login("Anonymous","myname@emailserver.com");
        System.out.println("YES!");
        File e=new File("test.txt");
        FileInputStream s=new FileInputStream(e);

        FTPFile[] list = f.listFiles();
        String cai="CARPETAINTERNET"; //folder I want to use
        while (done==0)
        {
            found=null;
            if (counter==1)
            {
                cai="CARPETAINTERNET";
            }
            else
            {
                cai="CARPETAINTERNET"+Integer.toString(counter); 
            }

            for (int i=0;i<list.length;i++)
            {
                if ((list[i].getType() == FTPFile.DIRECTORY_TYPE) && …
riahc3 50 Â Team Colleague

Sorry that was a question :)

My code or the code you posted wth "File" objects....?

riahc3 50 Â Team Colleague

OK, your code is better to deal with the problem (comparing if it is a file). :) Anyway, below is a suggestion code to add to your existing code.

My code or the code you posted wth "File" objects....

riahc3 50 Â Team Colleague

Im seeing problems with the code when it comes with FTP.

I used the Commons Net library:

http://commons.apache.org/net/

With these two objects: FTPClient and FTPFile.

http://commons.apache.org/net/api-3.1/org/apache/commons/net/ftp/FTPClient.html
http://commons.apache.org/net/api-3.1/org/apache/commons/net/ftp/FTPFile.html

I hardly will use the standard File Java object at all....

Could you please help me using FTP?

Thank you very much once again.

riahc3 50 Â Team Colleague

As a personal request please do not use this:

for (File lf : list2) {


if (lf.isDirectory()) { continue; }
++fileNumbers;          }

I understand it but it is no clear.

Also, Im trying to translate all the "file" variables to "FTPFile" variables....So god knows what code is going out...

riahc3 50 Â Team Colleague

Thanks a lot. Im gone in 20 mins so Ill have to analyze all that code tommorow because implementing it now would take too long

getCanonicalPath()

Seen a lot of functions that file has but Ill have to check this one out and see what it does (and see if it works when there is a ftpfile involved)

riahc3 50 Â Team Colleague

And if the folder does not exist, it makes the folder but doesnt put the file inside.

riahc3 50 Â Team Colleague

OK, it still writes to the folder even if it has more than 44....

riahc3 50 Â Team Colleague

Stupid code editor:

That like is

f.storeFile(f.printWorkingDirectory()+"/"+e.getName(),s);

That works. Let me test further.

riahc3 50 Â Team Colleague

New code:

public static void main(String[] args) throws SocketException, IOException 
    {

        int counter=1;
        FTPFile found;
        int done=0;
        FTPClient f=new FTPClient();
        System.out.println("Trying");
        f.connect("192.168.100.2");
        f.login("Anonymous","none");
        System.out.println("YES!");
        File e=new File("test.txt");
        FileInputStream s=new FileInputStream(e);

        FTPFile[] list = f.listFiles();
        String cai="folder";
        while (done==0)
        {
            found=null;
            if (counter==1)
            {
                cai="folder";
            }
            else
            {
                cai="folder"+String.valueOf(counter);
            }

            for (int i=0;i<list.length;i++)
            {
                if ((list[i].getType() == FTPFile.DIRECTORY_TYPE) && (list[i].getName()==cai))
                {
                    found=list[i];
                    break;
                }
            }


            if (found!=null)
            {
                f.changeWorkingDirectory("/"+found.getName());
                FTPFile[] list2 = f.listFiles();
                int files=0;
                for (int x=0;x<list2.length;x++)
                {
                    if (list2[x].getType()==FTPFile.FILE_TYPE)
                    {
                        files=files+1;
                    }
                }

                if (files<44)
                {
                    f.storeFile(f.printWorkingDirectory()+"/"+e.getName(), s);
                    done=1;
                }
                else
                {
                    counter=counter+1;
                }


            }//end if found not null

            else //if found equals null
            {
                f.makeDirectory("/"+cai);
                f.changeWorkingDirectory("/"+cai);
+"/"+e.getName()                f.storeFile(f.printWorkingDirectory(), s);
                done=1;
            }

        }//end while



    } //end main

Doesnt create the file inside the folder.

riahc3 50 Â Team Colleague

Also, I changed the found variable to be a File instead of a boolean in order to immediately deal with counting total file number

OK this changes :P

BTW, would it be a "File" or a "FTPFile"?

riahc3 50 Â Team Colleague

found <- a found directory

What is this variable exactly? It sounded like a true (1)/false (0) variable but now it sounds like you ment it is something else...

riahc3 50 Â Team Colleague

I have implemented it exactly the way this pseudo code does. I notice a couple points that may cause the problem you are encountering. 1) The file name must be different in order to create different file. One way to do is to pass in a number and append the number to the file name.
2) Permission denied may cause an exception that Java cannot create a file.
3) Do not reuse the list variable when you do file counting after you found a file. The reason is that if your folder is full, the same list would have already been changed.

1) This wont be a problem as the filename will always be different (this is a section of a bigger program; im just testing it out with this)
2) Nonissue. No permissions on target
3) I do 2 lists; The one that runs thru C:/ and then another one that goes thru C:/thefolder . Im not sure if thats what you ment

Did you look at my latest code? Is your pseudocode based on it or your own personal way?

riahc3 50 Â Team Colleague

Oops, my pseudo code is wrapping incorrectly. >_< Sorry. I will need to try to implement it to ensure the modified version. Brb...

Thats OK :) Thank you for helping me out with this. Driving me crazy!

riahc3 50 Â Team Colleague

Here is it:

public static void main(String[] args) throws SocketException, IOException 
    {




        File e=new File("test.txt");
        FileInputStream s=null;
            try 
            {


                e.createNewFile();

            } catch (IOException e2) {

                e2.printStackTrace();
            }

            try {

                s=new FileInputStream(e);

            } catch (FileNotFoundException e1) {
                System.out.println("error: " + e1.getLocalizedMessage());
            }

        FTPClient f=new FTPClient();

            System.out.println("Trying");
            f.connect("192.168.100.2");
            f.login("Anonymous","none");
            System.out.println("YES!");
            f.changeWorkingDirectory("/");
            FTPFile[] list = f.listFiles();
            String cai="folder";
            int found=0;
            int done=0;
            int counter=1;


            int files=0;

            int i=0;


            while (done==0)
            {
                if (counter==1)
                {

                    cai="folder";
                }

                else
                {

                    cai="folder"+String.valueOf(counter);
                }

                for (i=0;i<list.length;i++)
                {

                    if ((list[i].getType() == FTPFile.DIRECTORY_TYPE) && (list[i].getName().equals(cai)))
                    {

                        found=1;
                        //break; // WHAT IS THIS BREAKING EXACTLY??? THE IF OR THE FOR????
                    }

                    if (found==1)
                    {

                        f.changeWorkingDirectory("/"+cai);
                        FTPFile[] list2 = f.listFiles();
                        for (int x=0;x<list2.length;x++)
                        {

                            if (list2[x].getType() == FTPFile.FILE_TYPE)
                            {
                                files=files+1;

                            }

                        }
                        if (files<44)
                        {

                            f.storeFile(f.printWorkingDirectory()+"/test.txt", s);
                            done=1;
                        }
                        else
                        {

                            counter=counter+1;

                        }
                        files=0;

                    }
                    else if (found==0)
                    {

                        f.makeDirectory("/"+cai);
                        f.storeFile(cai, s);
                        done=1;                 
                    }

                } //end for

            } //end while
        } //end main

As you see Ive commented that break because Im not sure if that is really neccesary or what it is even breaking...

riahc3 50 Â Team Colleague

Will post new code shortly

riahc3 50 Â Team Colleague

OK some good news (not much but)

I have been able to count the files inside the folder. Less than 44, now it writes the file to the folder. If not, it doesnt do anything.

The next step would be since there are more than 44, it shoulds create a new folder and put it in there.

riahc3 50 Â Team Colleague

Here is the new code (based on what you put):

public static void main(String[] args) throws SocketException, IOException 
    {

        File e=new File("test.txt");
            try 
            {

                e.createNewFile();
            } catch (IOException e2) {

                e2.printStackTrace();
            }
        FileInputStream s=null;
            try {
                s=new FileInputStream(e);
            } catch (FileNotFoundException e1) {
                System.out.println("error: " + e1.getLocalizedMessage());
            }

        FTPClient f=new FTPClient();

            System.out.println("Trying");
            f.connect("192.168.100.1");
            f.login("Anonymous","none");
            System.out.println("YES!");
            f.changeWorkingDirectory("/");
            FTPFile[] list = f.listFiles();
            String cai="folder";
            int found=0;
            int done=0;
            int counter=1;


            int files=0; //file counter

            int i=0;


            while (done!=1)
            {
                if (counter==1)
                {
                    cai="folder";
                }

                else
                {
                    cai="folder"+String.valueOf(counter);
                }

                for (i=0;i<list.length;i++)
                {
                    if ((list[i].getType() == FTPFile.DIRECTORY_TYPE) && (list[i].getName().equals(cai)))
                    {
                        found=1;
                        break;
                    }

                    if (found==1)
                    {
                        f.changeWorkingDirectory("/"+cai);
                        FTPFile[] list2 = f.listFiles();
                        for (int x=0;x<list2.length;x++)
                        {
                            if (list2[x].getType() == FTPFile.FILE_TYPE)
                            {
                                files=files+1;
                            }

                        }
                        if (files<44)
                        {
                            f.storeFile(f.printWorkingDirectory(), s);
                        }
                        else
                        {
                            counter=counter+1;
                        }
                        files=0;    
                    }
                    else if (found==0)
                    {
                        f.makeDirectory("/"+cai);
                        f.storeFile(cai, s);
                        done=1;                 
                    }

                } //end for

            } //end while
        } //end main

Code only makes the first folder. Doesnt make/insert any file. When there is 45 files inside the folder, it doesnt do anything either.

riahc3 50 Â Team Colleague

Testing it doesnt work correctly as I tried putting 45 seconds and it doesnt create a new folder. It doesnt insert anything at all but it should....

riahc3 50 Â Team Colleague

OK, new code coming up.....Hang on a minute :)

riahc3 50 Â Team Colleague
public static void main(String[] args) 
    {
        File e=new File("hi.txt");
        try {
            e.createNewFile();
        } catch (IOException e2) {

            e2.printStackTrace();
        }
        FileInputStream s=null;
        try {
            s=new FileInputStream(e);
        } catch (FileNotFoundException e1) {
            System.out.println("Cant find file: " + e1.getLocalizedMessage());
        }

        FTPClient f=new FTPClient();
        try 
        {
            System.out.println("Trying");
            f.connect("192.168.100.1");
            f.login("Anonymous","none");
            System.out.println("YES!");
            f.changeWorkingDirectory("/");
            FTPFile[] list = f.listFiles();
            String cai="folder";
            int found=0;
            int done=0;

            int totalDIRS = 0;
            int files=0;
            int i=0;
            int n=0;

            do{
            System.out.println("i is " + i);
                for (i=0;i<list.length;i++)
                {
                     System.out.println("i inside the for " + i);
                    if (list[i].getType() == FTPFile.DIRECTORY_TYPE)
                    {
                        System.out.println ("Folder detected:" + list[i].getName());        
                        if (list[i].getName().equals(cai) || list[i].getName().equals(cai+String.valueOf(i))) 
                            {     
                            System.out.println ("Found folder I must go inside of: " + list[i].getName());  
                                    if (i==0)
                                        {
                                            System.out.println ("Changing dir " + list[i].getName());
                                            f.changeWorkingDirectory("/"+cai);  
                                            found=1;
                                        }
                                        else
                                        {
                                            System.out.println ("Changing dir with "+ i + " I am in: " + list[i].getName());
                                            f.changeWorkingDirectory("/"+cai+String.valueOf(i));    
                                            found=1;
                                        }

                                    if (found==1)
                                    {
                                        FTPFile[] list2 = f.listFiles();
                                        System.out.println ("Counting the files inside");
                                        for (int x=0;x<list2.length;x++)
                                        {
                                            files=files+1;
                                        }


                                        if (files<44)
                                        {
                                            System.out.println ("inserting file");
                                            f.storeFile(f.printWorkingDirectory(), s);
                                            done=1;
                                        }
                                        else
                                        {

                                        }
                                    }
                        }
                        else
                        {   
                            System.out.println ("Cant find folder");
                            if ((found==0) && (done!=1))
                            {
                                System.out.println ("Making folder");
                                f.makeDirectory("/"+cai);
                                found=1;
                                i=0;

                            }
                            else if ((i>0) && (found==0) && (done!=1))
                            {
                                System.out.println ("Making the folder with " + i);
                                f.makeDirectory("/"+cai+String.valueOf(i)); 
                                found=1;
                                i=0;
                            }

                        }
                    }
                }
                found=0;
            }while (done==0);



            System.out.println ("Done");
            f.logout();
            f.disconnect();



        } 
        catch (SocketException n) 
        {
            System.out.println("Socket exception: " + n.getLocalizedMessage());
        } 
        catch (IOException n) 
        {
            System.out.println("IOException: " + n.getLocalizedMessage());
        }

    }

Basically thats what I have.

It …

riahc3 50 Â Team Colleague

OK, I wrote some new code.....

Works somewhat. Creates the folder but doesnt put the file inside.

Will post in a min.

riahc3 50 Â Team Colleague

The thing is in this statement:

if (list[i].getName().equals(cai)) 
{
}

1: How do I "enter" directly into that directory (its path)?
2: How do I count the files inside that directory?

riahc3 50 Â Team Colleague

Your requirement is oddly worded... I assume that you are talking about adding "bye" file if there are less than 44 files...

Before going to the for-loop, outside the whole try-catch portion you posted, you need to create a flag and may name it as found, and then assign it to false. You also want to check whether or not the job is done by adding another flag named done and assign to false. Remember that found is corresponding to whether the specified directory exists and done is corresponding to the job is done. Also, create a counter and may assign as 1. The current code portion (besides the the declaration of FTPClient) of yours will be inside a while loop.

For the while-loop around the whole try, check its condition for not done. Inside it, if the counter is 1, the cai would be "hi" only. Else, the cai should be "hi"+counter (remember to convert it to string if there is any problem with concatenation).

In your for-loop, you must go through the whole list of the directory before you attempt to create a new directory. Go through the file list and check for directory only (you are doing it right now). If it is equal to the name, change the flag value (found) and break out of the loop. After the loop, check whether the flag is turned on. If it is, check for the number of files inside the directory; otherwise, create a new one and add …

riahc3 50 Â Team Colleague

Hello

Im trying to do some basic FTP work.

What I am trying to do is:

1: Search for a folder named "hi" in "C:". If hi exists, enter it. If it doesnt, create it THEN enter it.
2: Inside hi, count FILES and see if there is greater or less than 44. If there is less than 44, create a file named "bye" inside
3: If there is more than 44, I should make a "hi2" in C. Repeat step 2 and 3 with hi2..(if greater than 44)...3....(if greater than 44)......4..... (if greater than 44).....5

I think the general picture is captured.

For now I have this:

 FTPClient f=new FTPClient();
        try 
        {
            f.connect("192.168.100.1");
            f.login("user","pass");
            f.changeWorkingDirectory("/");
            FTPFile[] list = f.listFiles();
            String cai="hi";
            int totalDIRS = 0;
            int totalFILES = 0;
            int doesfolderexist=0;

            for (int i=0;i<list.length;i++)
            {
                if (list[i].getType() == FTPFile.DIRECTORY_TYPE)
                {
                    if (list[i].getName().equals(cai)) 
                    {

                    }
                    else
                    {   
                        f.makeDirectory(cai);
                        existcinternet=1;
                    }
                    System.out.println(list[i].getName());
                }
            }

For now, Im not sure where else to continue (as sad as it sounds)

Some hints?

Thank you

riahc3 50 Â Team Colleague

That was it JamesCherrill

riahc3 50 Â Team Colleague

Hello

I have the following:

String somestring="203/9834/345";
somestring.replace("/","");
System.out.println(somestring);

But it does not remove the slashes. How can I remove them?

Thanks

riahc3 50 Â Team Colleague

I disagree. Way too powerful if you want something simple.

If you 200% control PHP/JS/HTML, then Magento may be for you.

riahc3 50 Â Team Colleague

Hello

Magento is WAY too complicated for a small eCommerce. What is a powerful but a lot more simple eCommerce?

I perfer PHP since the (code) transition would not be too difficult....

riahc3 50 Â Team Colleague

Other than that, browser security settings may block them. I don't know Magento, so hope someone else can provide some insight.

My browser has default settings and this happens on more than one PC and more than one browser. It would be too much of a coincidence.

Magento is completely horrid not because of its lack of features but of its complexity...

riahc3 50 Â Team Colleague

Without anything else it will be hard to guess what's wrong.

My question was more if cookies had limitations and such. Your link was helpful in showing me that there are none (between offline and online)

Magento is a piece of shit basically :(

riahc3 50 Â Team Colleague

Although it is a intresting link, doesnt really answer much :)

Online it does not work and offline it does. This is using the same browsers on both instances (the offline and the online version). Ive revisted the code and they are exactly the same.

Using Firebug, I do think the cookie is stored/works so it may not be a cookie issue :S

riahc3 50 Â Team Colleague

Hello

Why does my cookie work offline but not offline? It simply stores text, nothing else.

Is there some limit that can be blocking it or something?

riahc3 50 Â Team Colleague

Hello

I want to be able to be on a page and have a favorite that points to http://localhost/export which is a web service. When I select that favorite, the current web page Im on should send all of its source code to the web service. The web service should "chop it up" and then return a excel document that should be downloadable.

I know how to do the web service and possibily how to chop up the code, manipulate it, and return the excel document that should be downloadable. I just dont know how I click that link in my favorites that gets all of the current page's source code and sends it to the web service to manipulate ti.

How can I do this?

Thanks

riahc3 50 Â Team Colleague

Hey

I want to make a Visual C++ program targeting x86 (and ARM) Windows CE .NET 4.20 using .NET Compact Framework. How do I do this?

Thanks

riahc3 50 Â Team Colleague

Hello

How do I write a C++ program targeting a x86 version of Windows CE in Visual Studio 2008? It doesnt show me Windows CE and more so, all it targets is ARM.

Thanks

riahc3 50 Â Team Colleague

This one is going to be intresting....

Im trying to access the method of BeginAcceptTcpClient in a System.Net.Sockets.TcpListener type of object but it seems that the 3.5 .NET Compact Framework does not support it.....

Is there a equivilent method or how can I emulate the method with other code?

Thank you

riahc3 50 Â Team Colleague

You can only do this if you perform an AJAX call from Javascript to PHP. You can stick to Javascript, if you use an encryption package.

I hate AJAX so I got a JS library and I am doing it with that.

riahc3 50 Â Team Colleague

Hey

I want to do something like this:

<script language="javascript">
                function calculatesha()
               {
               var name = document.getElementById("firstname").value;
               var last = document.getElementById("lastname").value;
               var complete = name+last;
               var hash = <?php echo(sha1(?>complete<?php));?>; 
               }
</script>

I hope the code is understood even if it is wrong.

Thanks.

riahc3 50 Â Team Colleague

How do I set the target to be a Windows CE .NET 4.20 machine in VS 2008?

riahc3 50 Â Team Colleague

Hello

Im having problems with the OS's FTP server so I want to write my own with its own possibilities.

The processor is x86 so it wont be for ARM or anything. The IDE is I imagine VS (2012). Some questions:

1) Where can I even start?
2) I choose C# because Im familiar with the language but is there any limitations, alternatives (such as any other .NET language), etc.
3) How do I comply for Windows CE .NET 4.20 from a Windows 7 x86 machine? What settings do I have to change in my IDE?
4) My GUI will be very simple: Stating a "home" directory, port, and a start/stop button. Nothing else.

Thanks for the help :)

riahc3 50 Â Team Colleague

Whats the best way to port a Java web service to a C# web service? Multiplatform.

Thanks

riahc3 50 Â Team Colleague

OK, no offense was intended, just a small hint to help you write better code. Please just ignore it if you wish.
J

I know and I know what you said is the exact same thing I put, I just consider it disrespectful to say that how a code is written is incorrect (in the sense of syntaxis, not logic of course). Everyone writes their code their own way. Just like the bracket debate of

if (something==something) { System.out.println("speak"); }

//VS

if (something==something){
System.out.println("speak");
}

//VS

if (something==something)
{
System.out.println("speak");
}

All the same thing just different writing styles.

riahc3 50 Â Team Colleague

One small point:
if ((some boolean expression) == true)
is horribly redundant. It's sufficient, and clearer, just to say
if (some boolean expression)

Im not going to get angry at that comment or anything but it has NOTHING to do with the topic at hand: Everyone writes code however they like.

riahc3 50 Â Team Colleague
        System.print.out("Hello");
        FTPClient client = new FTPClient();
        FileInputStream fis = null;
        try 
        {
            client.connect(ip);
            client.login(user, pass);
            try 
            {
                client.setFileType(FTP.BINARY_FILE_TYPE);
            } 
            catch (IOException e1) 
            {
                System.out.println("ERROR: Cannot change type of file( " +e1.getLocalizedMessage()+" )");
            }
            String filename = file;
            fis = new FileInputStream(filename);    

            boolean exists=client.changeWorkingDirectory(dir);
            if (exists==false)
            {
                client.makeDirectory(dir);
                client.storeFile(filename, fis);
                client.rename(filename, dir + filename);
            }
            else
            {
                client.storeFile(filename, fis);
                client.rename(filename, dir + filename);
            }
            client.logout();

        } 
        catch (IOException e) 
        {
            if (e.getLocalizedMessage().equals("Connection refused")==true)
            {
                System.out.println("Tried to connect but it refused connection. The IP is " + ip + " Check configuration and permissions.");
            }
            else
            {
                System.out.println("ERROR: A error has occured ( " +e.getLocalizedMessage()+" )"); //LINE 42
            }


        }
        finally
        {
            try
            {
                if (fis!=null)
                {
                    fis.close();
                }
                if (client.isConnected()==true)
                {
                    client.disconnect();
                }

            }
            catch (IOException e) 
            {
                System.out.println("ERROR: A error has ocurred when trying to close the file ( " +e.getLocalizedMessage()+" )");
            }
        }
        //Line 42 is printed out then the following:
        System.print.out("Bye");

I put the code without it being in a function as it is the same thing. Line 42 is printed then the following is but there is a long delay between. I dont want that delay to exist.

riahc3 50 Â Team Colleague

try - catch statements. but how are you expecting to proceed if the server is down?

:S The answer is pretty obvious: Dont send.

I already use try-catch statements:

public  void ftpupload(String ip, String user, String pass, String file, String dir)
    {

        FTPClient client = new FTPClient();
        FileInputStream fis = null;
        try 
        {
            client.connect(ip);
            client.login(user, pass);
            try 
            {
                client.setFileType(FTP.BINARY_FILE_TYPE);
            } 
            catch (IOException e1) 
            {
                System.out.println("ERROR: Cannot change type of file( " +e1.getLocalizedMessage()+" )");
            }
            String filename = file;
            fis = new FileInputStream(filename);    

            boolean exists=client.changeWorkingDirectory(dir);
            if (exists==false)
            {
                client.makeDirectory(dir);
                client.storeFile(filename, fis);
                client.rename(filename, dir + filename);
            }
            else
            {
                client.storeFile(filename, fis);
                client.rename(filename, dir + filename);
            }
            client.logout();

        } 
        catch (IOException e) 
        {
            if (e.getLocalizedMessage().equals("Connection refused")==true)
            {
                System.out.println("Tried to connect but it refused connection. The IP is " + ip + " Check configuration and permissions.");
            }
            else
            {
                System.out.println("ERROR: A error has occured ( " +e.getLocalizedMessage()+" )");
            }


        }
        finally
        {
            try
            {
                if (fis!=null)
                {
                    fis.close();
                }
                if (client.isConnected()==true)
                {
                    client.disconnect();
                }

            }
            catch (IOException e) 
            {
                System.out.println("ERROR: A error has ocurred when trying to close the file ( " +e.getLocalizedMessage()+" )");
            }
        }
    }

It fails (if the ip cannot be reached) and it executes the System.out.println("ERROR: A error has occured ( " +e.getLocalizedMessage()+" )"); line. I would need to display that and simply continue on. Nothing else.

riahc3 50 Â Team Colleague

Hello

Im using org.apache.commons.net's FTP object to make FTP transfers. The problem is that when the IP is down (example, the PC is turned off) a exception saying "No route to host" pops up and not only delays my program but gives a nasty error. How can I avoid this?

Thank you