what next to do in code?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: what next to do in code?

  1. #1
    Join Date
    Aug 2002
    Posts
    22

    what next to do in code?

    I want to send ftp or telnet commands on the Unix command box. I want to connect to say ftp enter user name and password and then run "ls" command

    Here is what I have written so far, code to ftp.
    But when I run the program I do not know what has happened? How can I do the next stage like enter "user name" "password" and finally run "ls" command for unix?????????
    import java.lang.*;
    import java.io.*;

    public class RuntimeFTP{

    public static void main(String[] arg){
    Runtime rt = Runtime.getRuntime();
    String[] callAndArgs = { "ftp.exe", "jaguar.wmin.ac.uk" };

    try
    {
    Process child = rt.exec(callAndArgs);
    child.waitFor();
    System.out.println("Process exit code is: " + child.exitValue() );
    }
    catch(IOException e)
    {
    System.err.println("IOException starting process!");
    }
    catch(InterruptedException e)
    {
    System.out.println("Interrupted waiting for process!");
    }
    }
    }

  2. #2
    Join Date
    Jul 2002
    Posts
    17

  3. #3
    Join Date
    Aug 2002
    Posts
    22
    rmlc

    Thanks this looks very interesting.
    I just hope now I can integrate one of these programs into something that I am working on.

    Speak to you later,

    bye for now

  4. #4
    Join Date
    Aug 2002
    Posts
    22
    Thank you for the link but the links have not been as fruitful as first anticipated. I would like to study the source code of an ftp or telnet client.

    The first link to ftp program the source code is illegible:
    http://remus.rutgers.edu/~jszabo/myjava/Ftp.html

    Whilst Bruce Blackshaw program at
    http://www.enterprisedt.com/downloads/ftp.html
    Has 3 folders and many classes making it very difficult to study the code.


    Finally the program at alpha-work does not provide any source code.
    http://www.alphaworks.ibm.com/ab.ns...82?OpenDocument

    I have done my own search on the web but I think I am not a good searcher on the search engine.

    I would be greatful for any more more links on ftp or telnet java program with source code, preferably one with easy to understand code.

    Thanks in advance.

  5. #5
    Join Date
    Aug 2002
    Posts
    22
    I want to integrate an ftp program into a program I am working on. I have scoured the net for reusebale code and come across a "t or Linlyn ftp program" which claims is easily integrateable into larger applications. The code is quite small so easy to understand.

    The problem is did does not seem to work and gives me errors. I would be grateful if someone could tell me why I am getting the error, here is the error:

    C:\My_DL_Dap\ftp in java>appletviewer t.java
    Warning: <applet> tag requires width attribute.
    java.security.AccessControlException: access denied (java.net.SocketPermission j
    aguar.wmin.ac.uk resolve)
    at java.security.AccessControlContext.checkPermission(AccessControlConte
    xt.java:270)
    at java.security.AccessController.checkPermission(AccessController.java:
    401)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
    at java.lang.SecurityManager.checkConnect(SecurityManager.java:1042)
    at java.net.InetAddress.getAllByName0(InetAddress.java:909)
    at java.net.InetAddress.getAllByName0(InetAddress.java:890)
    at java.net.InetAddress.getAllByName(InetAddress.java:884)
    at java.net.InetAddress.getByName(InetAddress.java:814)
    at java.net.InetSocketAddress.<init>(InetSocketAddress.java:109)
    at java.net.Socket.<init>(Socket.java:118)
    at Linlyn.ftpConnect(t.java:326)
    at Linlyn.<init>(t.java:236)
    at t.init(t.java:83)
    at sun.applet.AppletPanel.run(AppletPanel.java:341)
    at java.lang.Thread.run(Thread.java:536)


    I would also be grateful if someone could try out the propgram and tell me if it works for them, then I could determine if it is because ftp clients are being blocked by my server. The ftp program is very small, here is the url:

    http://www.afu.com/jdownload.html

    1) compile the code
    2) fill in everywhere it requests "your-server" "username" and "password"
    3) to run appletviewer t.java

  6. #6
    Join Date
    Aug 2002
    Posts
    94
    Hi,
    this is more of a question than solution. I have no experience on this but my doubt is based on my general knowledge of Java and networking. In your code you are calling an external program called ftp.exe and executing it. If my understanding of your requirement is correct then then why do you need this (any advantage?) i.e. call an external FTP program when you can create a socket directly to your FTP host on port 21 for FTP connection and work out suitable code to handle "username" & "password".

    String[] callAndArgs = { "ftp.exe", "jaguar.wmin.ac.uk" };

    try
    {
    Process child = rt.exec(callAndArgs);

    When you run an external program (ftp.exe) then you have to pass on arguments (FTP host address,username,password) to this program and not to the host directly because your java code is not requesting a connection to the FTP host.

    Bye
    Pankaj

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center