java - Fail to upload file using ftp4j -


i'm using ftp4j ftp client.

ftpclient client = new ftpclient(); client.connect("86.22.11.178"); client.login("usr", "pwd"); client.changedirectory("/dir"); client.upload(file); 

it works fine @ localhost, not work when enclosed in jsf web application deployed on web server. succeeded connect , login, when code reaches upload command, skips on , nothing. no exception been thrown.

there full conectivity ftp server, can't problem. have set chmod 777 permission on files , belong same owner.

this code worked on windows machine, machines running on linux have different "rules"?

your code seems correct. try find out ftp error throws. timeout may happens, faced!!!

import org.apache.commons.net.ftp.;
import java.io.
;

/** * class used demonstrate usage of jakarta commons net package */
public class testftp {

/** creates new instance of testftp */   public testftp() {   }    /**   * main - unit test program   * @param args command line arguments   *   */   public static void main(string args[]) {       try {           string ftphost = "157.227.38.131";           string ftpusername = "firebird";           string ftppassword = "tcs@12345";           string ftpremotedirectory = "/etc/vlp/uploaded_files";           string filetotransmit = "c:\\temp\\vlpdyn18022010174439.an";            //create jakarta commons net ftp client object           ftpclient ftp = new ftpclient();            //a datatype store responses ftp server           int reply;            //           //connect server           //           ftp.connect(ftphost);            //           // after connection attempt, should check reply code verify success.           //           reply = ftp.getreplycode();               if(!ftpreply.ispositivecompletion(reply)) {               try {                   ftp.disconnect();               } catch (exception e) {                   system.err.println("unable disconnect ftp server " +                                      "after server refused connection. "+e.tostring());               }               throw new exception ("ftp server refused connection.");           }                         system.out.println("connected " + ftphost + ". "+ftp.getreplystring());            //           //try login           //           if (!ftp.login(ftpusername, ftppassword)) {               throw new exception ("unable login ftp server " +                                    "using username "+ftpusername+" " +                                    "and password "+ftppassword);           }            system.out.println(ftp.getreplystring());           system.out.println("remote system " + ftp.getsystemname());            //           //set our file transfer mode either ascii or binary           //           //ftp.setfiletype(ftp.ascii_file_type);           ftp.setfiletype(ftp.binary_file_type);            //           //change remote directory           //           if (ftpremotedirectory != null && ftpremotedirectory.trim().length() > 0) {               system.out.println("changing ftp remote dir: " + ftpremotedirectory);               ftp.changeworkingdirectory(ftpremotedirectory);               reply = ftp.getreplycode();                if(!ftpreply.ispositivecompletion(reply)) {                   throw new exception ("unable change working directory " +                                        "to:"+ftpremotedirectory);               }           }            //           //get file transfer , send it.           //           file f = new file(filetotransmit);           system.out.println("storing file remote filename: " + f.getname());           boolean retvalue=true;          try{            retvalue = ftp.storefile(f.getname(), new fileinputstream(f));          }catch(exception e){e.printstacktrace();}           if (!retvalue) {             throw new exception ("storing of remote file failed. ftp.storefile() returned false.");           }            //disconnect ftp server           //           try {               //ftp.logout();               ftp.disconnect();           } catch (exception exc) {               system.err.println("unable disconnect ftp server. " + exc.tostring());           }        } catch (exception e) {           system.err.println("error: "+e.tostring());       }        system.out.println("process complete.");       system.exit(0);   }       

}


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -