hello all
i use commons-net-2.2.jar for connection to my FTP account and managing my directories and uploading files on the remote server
i use the below statements for 1- connecting to my ftp account of my host 2- listing files on the htdocs/images directory of my host and 3-uploading a file on my host
firstly i import this classes from commons-net.jar to my servlet
Java Code:
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
then i connet from ftp protocol to the remote host
Java Code:
FTPClient client = new FTPClient();
            // Connect to the FTP server as anonymous
            client.connect("www.salekan.ir");// setting ftp host
            client.login( "MyUsername", "MyPassword" ); //setting ftp username and password
            client.setFileType(FTP.BINARY_FILE_TYPE);
            String remoteDir = "/htdocs/images";
            client.changeWorkingDirectory(remoteDir);// change working directory to htdocs/images
            int reply=client.getReplyCode();
            if(FTPReply.isPositiveCompletion(reply)){// testing the connection
                out.print("Connected Success...<br/>");
            }
then listing the files on the htdocs/images directory by this statements
Java Code:
FTPFile[] remoteFiles = client.listFiles();//listing files on the folder to a array
            out.print( "Files in " + remoteDir+" count= "+ remoteFiles.length +"<br/>" );
            for (int i = 0; i < remoteFiles.length; i++) {
                String name = remoteFiles[i].getName( );
                long length = remoteFiles[i].getSize( );
                out.print( name + ":\t\t" + length +"<br/>" );
            }
and finally i tried to upload text1.txt file to the working directory of the remote server and then disconnect
Java Code:
File file=new File("c:\\text1.txt");
            if(file.isFile()){
                out.print("<br/>"+file.getName()+"<br/>");
                InputStream in=new FileInputStream(file);
                client.storeFile(file.getName(), in);
                out.print("Uploading Success");
            }
            client.disconnect( );
when i run this web app and this servlet on my computer and localhost this servlet execute correctly and the file upload on the server correctly
but when i send this web app and run from there step1: connecting to the host using ftp protocole and step2: listing the files execute correctly but step3:uploading file on the server dont run and don't send any errors(run incorrectly)