Running ftp in java

I am actually still working on how to call the ftp program in linux from a java application:
And came up wif this:
String s;
try
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("ftp");
BufferedReader in = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader err = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
PrintWriter out = new PrintWriter(new
OutputStreamWriter(p.getOutputStream()));
out.print("open strawberry.homeftp.net \n");
out.print("user\n");
out.print("password \n");
out.print("dir \n");
out.print("quit \n");
out.flush();
while((s=in.readLine())!=null)
System.out.println(s+"\n");
out.close();
catch(IOException io) {}
However, i get the Password prompt when i run it and it will login to the ftp when i gave the correct password.
But is there any other way to pass the password in without having to type it in the command line?
I desperately need to fix this :(...Can someone help?

I don't know the ftp client you are using
the command line arguments here are:
usage: ftp [-AadefginpRtvV] [-o outfile] [-P port] [-r retry]
[-T dir,max[,inc][[user@]host [port]]] [host:path[/]]
[file:///file] [ftp://[user[:pass]@]host[:port]/path[]]
[http://[user[:pass]@]host[:port]/path] [...]
ftp -u url file [...]
i.e. your can use:
   Process p = rt.exec("ftp ftp://user:[email protected]");but why not using the apache commons net libray http://apache.serveftp.org/apache-site/dist/jakarta/commons/net/binaries/commons-net-1.1.0.tar.gz
it has a java ftp client.

Similar Messages

  • Running ftp from runtime exec()

    How would I run ftp from exec()? Can I run a script that is ftping from exec()? Why would anyone go through the trouble of writing their own ftp code, if you can just call a script from the exec() method? I am going to be running ftp from a servlet to send a file to a mainframe, where it will run and create an xml file that the servlet will then post to the screen. should I be using java's ftp commands, or will my script way work fine?
    Thanks

    How would I run ftp from exec()?Like any other program. It would be good to read the article http://www.javaworld.com/jw-12-2000/jw-1229-traps.html first to get it right the first time.
    Can I run a script that is ftping from exec()?I don't see any objections.
    Why would anyone go
    through the trouble of writing their own ftp code, if
    you can just call a script from the exec() method?Good question. 1) you are making your application platform dependent by using a platform depenent program 2) Runtime.exec() can't be used in applets but ftp over a socket connection is possible 3) There are already good packages for it (eg. at www.fooware.com) written for it so you don't need to write anything yourself (and 4: just because it's fun!)
    I am going to be running ftp from a servlet to send a
    file to a mainframe, where it will run and create an
    xml file that the servlet will then post to the
    screen. should I be using java's ftp commands, or
    will my script way work fine?
    If you have a working script and you know you will work on only one platform calling a script with exec will be just fine.

  • Jdevloper11g Release 1: Error while running Bean in java

    Hello ,
    I am getting error while running my HRFacadeClient.java
    [EclipseLink/JPA Client] Adding Java options: -javaagent:C:\Oracle\Middleware\jdeveloper\..\modules\org.eclipse.persistence_1.1.0.0_2-1.jar
    "C:\Program Files\Java\jdk1.6.0_29\bin\javaw.exe" -client -classpath C:\JDeveloper\mywork\HR_EJB_JPA_APP\.adf;C:\JDeveloper\mywork\HR_EJB_JPA_APP\EJBModel\classes;C:\Oracle\Middleware\modules\com.oracle.toplink_1.1.0.0_11-1-1-6-0.jar;C:\Oracle\Middleware\modules\org.eclipse.persistence_1.2.0.0_2-3.jar;C:\Oracle\Middleware\modules\com.bea.core.antlr.runtime_2.7.7.jar;C:\Oracle\Middleware\modules\javax.persistence_1.1.0.0_2-0.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.xdk_11.1.0\xmlparserv2.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.xdk_11.1.0\xml.jar;C:\Oracle\Middleware\modules\javax.jsf_1.1.0.0_1-2.jar;C:\Oracle\Middleware\modules\javax.ejb_3.0.1.jar;C:\Oracle\Middleware\modules\javax.enterprise.deploy_1.2.jar;C:\Oracle\Middleware\modules\javax.interceptor_1.0.jar;C:\Oracle\Middleware\modules\javax.jms_1.1.1.jar;C:\Oracle\Middleware\modules\javax.jsp_1.3.0.0_2-1.jar;C:\Oracle\Middleware\modules\javax.jws_2.0.jar;C:\Oracle\Middleware\modules\javax.activation_1.1.0.0_1-1.jar;C:\Oracle\Middleware\modules\javax.mail_1.1.0.0_1-4-1.jar;C:\Oracle\Middleware\modules\javax.xml.soap_1.3.1.0.jar;C:\Oracle\Middleware\modules\javax.xml.rpc_1.2.1.jar;C:\Oracle\Middleware\modules\javax.xml.ws_2.1.1.jar;C:\Oracle\Middleware\modules\javax.management.j2ee_1.0.jar;C:\Oracle\Middleware\modules\javax.resource_1.5.1.jar;C:\Oracle\Middleware\modules\javax.servlet_1.0.0.0_2-5.jar;C:\Oracle\Middleware\modules\javax.transaction_1.0.0.0_1-1.jar;C:\Oracle\Middleware\modules\javax.xml.stream_1.1.1.0.jar;C:\Oracle\Middleware\modules\javax.security.jacc_1.0.0.0_1-1.jar;C:\Oracle\Middleware\modules\javax.xml.registry_1.0.0.0_1-0.jar;C:\Oracle\Middleware\modules\javax.persistence_1.0.0.0_1-0-2.jar;C:\Oracle\Middleware\wlserver_10.3\server\lib\weblogic.jar -Djavax.net.ssl.trustStore=C:\Oracle\Middleware\wlserver_10.3\server\lib\DemoTrust.jks -javaagent:C:\Oracle\Middleware\jdeveloper\..\modules\org.eclipse.persistence_1.1.0.0_2-1.jar oracle.HRFacadeClient
    Error occurred during initialization of VM
    agent library failed to init: instrument
    Error opening zip file or JAR manifest missing : C:\Oracle\Middleware\jdeveloper\..\modules\org.eclipse.persistence_1.1.0.0_2-1.jar
    Process exited with exit code 1.
    plz help me to solve this issue.

    If you have addition error detail or stack-traces, please consider posting those.
    Verify that you have not unintentionally corrupted your project XML files, especially by editing them with a rogue editor, e.g. Windows Notepad is known to add a BOM to a file if you save as UTF-8.

  • Error while downloading through ftp using Java

    I have attempted to download a file using ftp through java this is my code
    import sun.net.www.protocol.ftp.FtpURLConnection;
    import sun.net.ftp.FtpClient;
    import sun.net.TelnetInputStream;
    import java.net.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    public class PasswordedPageViewer {
    public static void main (String[] args) {
    try {
    //Open the URLConnection for reading
    FtpClient cli = new FtpClient();
    cli.openServer("mycgiserver.com", 21);
    cli.login("//Username//", "//password//");
    TelnetInputStream ins = cli.get("mail.jsp");
    BufferedReader d = new BufferedReader(new InputStreamReader(ins));
    while(d.readLine().length()>0){
    System.out.println(d.readLine());
    catch (MalformedURLException e) {
    System.err.println(args[0] + " is not a parseable URL");
    catch (IOException e) {
    e.printStackTrace();
    System.err.println(e);
    } // end main
    } // end SourceViewer2
    But this keeps failing and returning the following error message
    sun.net.TelnetProtocolException: misplaced CR in input
         at sun.net.TelnetInputStream.read(TelnetInputStream.java:96)
         at sun.net.TelnetInputStream.read(TelnetInputStream.java:130)
         at sun.net.TelnetInputStream.read(TelnetInputStream.java:115)
         at java.io.InputStreamReader.fill(InputStreamReader.java:173)
         at java.io.InputStreamReader.read(InputStreamReader.java:249)
         at java.io.BufferedReader.fill(BufferedReader.java:139)
         at java.io.BufferedReader.readLine(BufferedReader.java:299)
         at java.io.BufferedReader.readLine(BufferedReader.java:362)
         at PasswordedPageViewer.main(PasswordedPageViewer.java:30)
    sun.net.TelnetProtocolException: misplaced CR in input
    Can anyone help

    Even so. Try simplifying. You only need one sun.* class:
    import java.io.*;
    import sun.net.ftp.FtpClient;
    public class FtpGet {
    public static void main( String[] argv ) throws Exception {
    FtpClient c = new FtpClient();
    c.openServer( "ftp.yourplace.com" );
    c.login( "user", "password );
    InputStream in = c.get( "yourFile.txt" );
    BufferedReader r = new BufferedReader(new InputStreamReader(in));
    String line = r.readLine();
    while ( null != line ) {
    System.out.println( line );
    line = r.readLine();
    }

  • How to run the simple java card program in eclipse?

    I am trying to run a simple HelloWorld program in eclipse 3.5 having java card development kit 2.2 installed in it.
    Firstly,I go to the JCWDE tab and press start..then when trying to deploy that package its giving me error like " com.hw.HelloWorld: unsupported class file format of version 50.0." can any one help me in this what is this error???n how to resolve n run this program..

    Hi,
    It is because the converter works on byte code and it only supports a subset of the Java language (see the JC specifications). It is kind of like compiling you code on Java 6 and trying to run it on Java 5. The JCDK outlines the required compiler version.
    Cheers,
    Shane

  • How to run the imported java class in form

    Help!!!!!
    Pls help me to run the imported java class in forms.
    Package is created in forms while imported one class called
    singlexml.class and that package has one procedure and one
    function.
    I just wanted to run that class.I mean the new package.
    Thanks
    Anil

    Hi,
    It is because the converter works on byte code and it only supports a subset of the Java language (see the JC specifications). It is kind of like compiling you code on Java 6 and trying to run it on Java 5. The JCDK outlines the required compiler version.
    Cheers,
    Shane

  • How to run a pure java application client with ear deployed on 9ias

    Hello all,
    We want to run a pure java application client which is packed with target bean in the same ear file. In the application-client.xml we refer to some EJBs.
    We deployed the ear file which contains ejb jar module and application client module to oracle 9ias 904 through enterprise manager on unix. The jndi.properties we used looks like this
    java.naming.factory.initial=com.evermind.server.rmi.ApplciationClientInitialContextFactory
    java.naming.provider.url=opmn:ormi://opmn_host:opmn_port:oc4j_instance_name/application_name
    java.naming.security.principal=test
    java.naming.security.credentials=test
    Is there anybody knows how to run such an application client? Do we need to provide such a jndi.properties or not at all?
    Thanks,
    9ias user

    Refer OpenEJB User - Oracle ADF Essential and TomEE+
    Also refer Bug in tomee 1.5.2. Fixed in 1.6.
    https://issues.apache.org/jira/browse/TOMEE-756

  • Do i need a network card to install and run a local java web server

    Friends,
    Do i need a network card in my computer to install and run a local Java Web Server or any Web Server.

    network cards are only for connecting equipment together... you can set up a webserver without any more equipment than you have already! Indeed Tomcat... BUT you would be better off with apache for production stuff. It depends what you need to serve... if its mainly static pages (i guess it probably isn't) then apache will be enough by itself; but if you need to serve dynamic pages (JSP, Servlet blah blah) then you will need tomcat. Tomcat has it's own webserver and its perfectly ok for testing or low-load stuff, but you can integrate with Apache (a moderately compex task, but do-able, see tomcat-user forum off of apache site) for greater stability, and you don't have to show the port in the URL... Don't set up a webserver on any pc that contains stuff you don't want hacked into... it becomes very succeptible when the service is up...

  • Unable to run FTP scipt

    Hi All,
    I want to FTP files from windows network shared drive(Windows NT) to remote SAP system(UNIX system) via ABAP program. I wrote a FTP Scipt files in a ABAP program and executing them.  Our SAP application server is running on Windows NT and central instance is running on UNIX server.
    When i run the program on application server(WINDOWS NT),  FTP script file (for opening connection etc) is successfully executing through program. Where as when i run this program on central instance(UNIX), am unable to connect to remote system ( 'open' command).
    Can u please suggest me how to handle this...

    Configure your FTP server to send it's public IP address in the PASV response and define a static PASV port range.  You must then open the PASV range inbound in addition to port 990 (assuming you're using FTPS on the default port) for the clients who need to connection.  If you're running FTPS on port 21, you'll need to make sure that FTP inspection is disabled.

  • Error running command: /usr/java/bin/java: error execing process: Not enoug

    Error running command: /usr/java/bin/java: error execing process: Not enough space
    In a whole root zfs zone the webconsole service fails to start. This is what I get:
    svc:/system/webconsole:console (java web console)
    State: maintenance since Fri Aug 27 14:32:41 2010
    Reason: Start method exited with $SMF_EXIT_ERR_FATAL.
    See: http://sun.com/msg/SMF-8000-KS
    See: man -M /usr/share/man -s 1M smcwebserver
    See: /var/svc/log/system-webconsole:console.log
    Impact: This service is not running.
    # more /var/svc/log/system-webconsole:console.log
    ^C# more /var/svc/log/system-webconsole:console.log
    [ Aug  6 09:30:40 Disabled. ]
    [ Aug  6 09:30:40 Rereading configuration. ] [ Aug  6 09:30:52 Enabled. ] [ Aug  6 11:32:50 Enabled. ] [ Aug  6 11:33:02 Executing start method ("/lib/svc/method/svc-webconsole start"
    Starting Sun Java(TM) Web Console Version 3.1 ...
    The console is running.
    [ Aug  6 11:33:25 Method "start" exited with status 0 ] [ Aug 27 14:32:15 Enabled. ] [ Aug 27 14:32:28 Executing start method ("/lib/svc/method/svc-webconsole start"
    Error running command: /usr/java/bin/java: error execing process: Not enough spa ce [ Aug 27 14:32:41 Method "start" exited with status 95 ] # df -k
    Filesystem kbytes used avail capacity Mounted on
    / 0 4341506 3761710 54% /
    /dev 8103216 4341506 3761710 54% /dev
    proc 0 0 0 0% /proc
    ctfs 0 0 0 0% /system/contract
    mnttab 0 0 0 0% /etc/mnttab
    objfs 0 0 0 0% /system/object
    swap 2498344 360 2497984 1% /etc/svc/volatile
    /platform/SUNW,T5240/lib/libc_psr/libc_psr_hwcap2.so.1
    8103216 4341506 3761710 54% /platform/sun4v/lib/libc_psr.so.1
    /platform/SUNW,T5240/lib/sparcv9/libc_psr/libc_psr_hwcap2.so.1
    8103216 4341506 3761710 54% /platform/sun4v/lib/sparcv9/libc_psr.so.1
    fd 0 0 0 0% /dev/fd
    swap 2497984 0 2497984 0% /tmp
    swap 2498024 40 2497984 1% /var/run
    Grp-MFNY/billables/RV
    20514816 22 3761710 1% /RV
    Grp-MFNY/billables/TT_DB
    20514816 28 3761710 1% /TT_DB
    Grp-MFNY/billables/tab

    You need to find the java exceptions - most likely in the logs in the /var/log/webconsole/console directory.
    A wild guess is you don't have enough swap space to perform a fork.
    -- Ken

  • How to open directory in run time using java

    Hi All
    i hava problem for open a directory in run time in java.please help me with code.

    Please elaborate what you mean by opening a directory. You can at all times access directory content via the File class.
    File myDir=new File(<pathToDir>);
    File[] directoryContent=myDir.listFiles();

  • How to run the deployed java file

    Hi friends
    please guide me hoe to run the deployed Java class file on the machine on which the java sdk is not installed please tell me also the it is necessary to change environment variables
    becoz i have created one small package & i want to deploy & capable to work it on machine on which there is no java SDK is installed

    Does your application have a GUI (e.g. Swing or AWT)? Can you distribute it from a web site?

  • Running a plain java class in command prompt which uses third party jars

    i have to run a simple java class. its actually a process which is running in the background. Now to run this java file i have created a batch file. my problem is that this java file uses around 100 jar files. when i try to run this java file (actually .class file) it gives me no class defination found error for this java(class) file. What can be the problem. My java home is set....how to solve this problem

    i have to run a simple java class
    my problem is that this java file uses around 100 jar filesThese two statements are contradictory.
    it gives me no class defination found error for this java(class) file. What can be the problemThe class is not on the classpath.
    how to solve this problemEnsure all classes are on the classpath.
    I bet if your searched this forum (or even read the java tutorial) you'd find something .

  • How to avoid the run time error  "java.lang.OutOfMemoryError"

    hi
    i have written a code to read a txt file ,i used FileReader to read a file . the code is working well for small txt files. but when i tried to read a large file(greater than 2MB), a run time error called "java.lang.OutofMemoryError" appeared .
    plz suggest the methods to read txt files of large capacity(greater than 25MB) .if possible give an example.

    thanks for ur replies
    i am new to java programming .i am a student persuing B.Tech final semester .i got struck in my project while reading a large txt file(greater than 3MB) . i am now giving a part of code that i had used in my project .it working fine with the txt files less than 3MB ,but when i am treing to read a file greater than 3MB , it is displaying a run time error "java.lang.outofmemoryerror"
    i have tried using "java -Xmx" ,it is working , but is there any better option ??
    here is the part of code:
       FileReader fin;
        al=new ArrayList();
         try
              fin=new FileReader(filename);
         catch(FileNotFoundException e)
           System.out.println("File not foumn");
         return;
    while((i=fin.read())!=-1)
           al.add(new Character((char)i));
         fin.close(); 
         Object obj[]=al.toArray();plz help me
    --santosh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • My accounts program won't run without legacy Java SE6 runtime since I upgraded to OS x Yosemite but I can't download it

    My "Solar" accounts program won't run without "legacy Java SE6 runtime" since I upgraded my iMac desktop to OS x Yosemite but I can't download it, nothing happens when you click on the link to apple support

    Okay, I'm not a Genius, but, I'm smarter than the one I spoke to at the Apple Store.They told me that they couldn't help me with Legacy Java SE6 Runtime. Adobe has the worst support in the industry so don't call them.
    If you have a Time Machine backup, go to one that pre dates your install of Yosemite. Go to the System/Library/Java and drag copy the folder to your internal hard disk. Now you will need the Administrator password. Once copied, drag the old Java folder into your System/Library folder and when asked to replace, click OK. Restart your Mac and you will have use of your software that requires Legacy Java SE6 Runtime.
    I'm totally done with Apple since they are trying to box me into a corner. Have fun kids.

Maybe you are looking for

  • How to sort a column of type CHAR

    Hi, I have a report for which the o/p is displayed in ALV grid format.There is one column in the O/p strcuture which is "No of days".Based on certain conditions,i need to display the value for some of the days as Negative e.g. " - 45".Becasuse of thi

  • Production Order - Trigger won't Auto Refresh

    2007A PL49 - Just upgraded from 2005A I have the following query set in a UDF on the Production Order. SELECT T1.PriceAfVAT FROM ORDR T0 INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry WHERE T1.ItemCode = $[$-6.0.0] and T0.DocNum = $[$-32.0.0] The qu

  • Can I keep plugging in my iphone to the power supply despite fully charged to reduce the battery cycle?

    Since an iphone battery lasts for 300-500 cycles before losing its juice, can I just continuously connect my iphone to the power supply to avoid using the battery, like how I use my macbook.

  • Using songs as ringtones?

    When I buy a song from Itunes, is there a way I can use that as a ringtone? If not how do I get that same song as a ringtone, or any normal songs? When I go to the Itunes store, it seems like all there is for ringtones are like sounds of animals, car

  • Is NetBeans (IDE) for lazy people or what?

    why NetBeans (IDE) or Manual Coding which is better and why? because i dont seem to enjoy netBeans anyone please tell me benifits (IDE) has over Manual Coding excluding time factor.