Perl to Java translation

What is the java equivalent of the following perl code?#!/usr/bin/perl
use strict;
use warnings;
use Net::FTP;
my $file = shift;
my $server = 'domain.com'; (edited out)
my $username = 'username'; (edited out)
my $password = 'password'; (edited out)
my $remote_dir = 'domain.com'; (edited out)
my $ftp = Net::FTP->new($server) or die "can't connect to $server: $@";
$ftp->login($username, $password) or die "can't login ", $ftp->message;
$ftp->cwd($remote_dir) or die "can't cd to $remote_dir ", $ftp->message;
$ftp->put($file) or die "can't transfer $file", $ftp->message;
$ftp->quit;
exit 1;Thank you!

http://www.google.com/search?q=FTP+Java

Similar Messages

  • Embedding perl in Java

    Are there any good websites/tutorials about how to go about embedding/using perl code in Java?
    How is it done?
    thanks, B.

    Are there any good websites/tutorials about how to go
    about embedding/using perl code in Java?
    How is it done?
    thanks, B. Try these links:
    http://www.perl.com/cs/user/query/q/6?id_topic=29
    http://www.perldoc.com/perl5.6/pod/perlfaq3.html#How-can-I-compile-Perl-into-Java-

  • Perl from java

    hi ..
    i want to generate a graphical report after anlysing a log file... i have parsed it with perl....but how do u get the return values into the java prog to generate the graphical report..
    pls help me... i am new to perl with java........

    How about writing the perl script such that it outputs a file of data, then write a java program that reads the data and plots it?

  • Perl - c - java munmap_chunk(): invalid pointer

    I am trying to use the JNI invocation interface from within some C code which in turn is invoked from Perl (Perl -> C -> Java).
    The problem is, when the Perl process ends, i end up this:
    *** glibc detected *** /usr/bin/perl: munmap_chunk(): invalid pointer: 0xb68d3880 ***
    ======= Backtrace: =========
    /lib/i686/cmov/libc.so.6(+0x6b321)[0xb7e20321]
    /lib/i686/cmov/libc.so.6(+0x6c59e)[0xb7e2159e]
    /usr/bin/perl(perl_destruct+0x1290)[0x807dd30]
    /usr/bin/perl(main+0x95)[0x80642a5]
    /lib/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xb7dcbc76]
    /usr/bin/perl[0x8064171]
    I am simply invoking this function once, which creates the JVM and later invokes DestroyJavaVM...
    static void test( void ) {
        JavaVM *jvm;
        JNIEnv *env;
        JavaVMInitArgs vm_args;
        JavaVMOption options[ 1 ];
        options[ 0 ].optionString = "-Djava.class.path=/tmp";
        vm_args.version = JNI_VERSION_1_6;
        vm_args.nOptions = 1;
        vm_args.options = options;
        vm_args.ignoreUnrecognized = 0;
        int ret = JNI_CreateJavaVM( &jvm, ( void** ) &env, &vm_args );
        if(ret < 0)
            printf("\nUnable to Launch JVM\n");
        else {
            if( (*env)->ExceptionOccurred( env ) )
               (*env)->ExceptionDescribe( env );
            (*jvm)->DestroyJavaVM( jvm );
    }Can anyone offer me any clues as to what may be happening here? I am guessing that DestroyJavaVM is not freeing the resources allocated by the JVM and this interferes with garbage collection in Perl...

    I am guessing that DestroyJavaVM is not freeing the resources allocated by the JVMThat definitely won't be it, as DestroyJavaVM() currently does nothing.
    I would take this in three steps:
    1. write a C main() that starts and stops the JVM correctly
    2. write a C test() that does nothing except get called by Perl correctly
    3. Have the test() start the JVM using the same code as at (1).
    I would also have a look at how you are building the C exe. In my experience on Windows, sharing the C RTL doesn't work in conjunction with the JVM. Some years ago I was a whizz at fixing this sort of thing but these days I just use a static library ;-)

  • Can i write on perl in java?

    can i write on perl in java?

    can i write on perl in java?Listen Sscotties, not to step on too many of your toes, but if you are going to answer the question, do it write. He did not ask how to write perl, but how to write on perl. So here is the REAL answer:
    public class IThinkThisIsHowWeWouldWritePerlInJava{
       public static void main(String []args){
         System.out.print("on perl"); // not 100% sure though, maybe someone else could help
    }

  • Interacting with perl through java.

    I'm trying to do something with Java that I haven't managed to do until now. I'm trying to interact with a perl process giving him input and reading output.
    I have a perl module that has several functions and the idea is to launch a process in a java program with the following line :
    perl -e 'while(<STDIN>) { eval $_ ; }'
    and then give the process the necessary input and the read the given output.
    For instance with the above line you can do the following:
    [user@host ~]$ perl -e 'while(<STDIN>) { eval $_ ; }'
    print "Hello World\n";
    Hello World
    Here is the code I'm using:
    import java.io.BufferedReader;
    public class ExecProgram {
    private static Runtime runtime;
    private static Process process;
    public static void main(String[] args) {
         runtime = Runtime.getRuntime();
         try {
         process = runtime.exec("/usr/bin/perl -e 'while(<STDIN>) { eval $_ ; }'");
              process = runtime.exec(cmd);
         } catch (IOException e) {
              System.err.println("Error executing process");
         PrintWriter out = new PrintWriter(process.getOutputStream());
         String commandLine = "print \"Hello World\n\"";
         out.println(commandLine);
         BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
         try {
         String line;
         while ((line = in.readLine()) != null)
              System.out.println("Output: "+line);
         } catch (IOException e) {
         System.err.println("Error reading output");
    As you can see I'm using Runtime class to interact with the process but nothing happens if replace the exec line with:
    process = runtime.exec("ls");
    I can see in the output the listing of the current directory.
    Have you ever tried something like this? Is this the correct way for doing this?

    Have you ever tried something like this? I have. Here's a rough sample:
        public static void main(String[] args) throws Exception {       
            String[] cmd = new String[]{
                "/usr/bin/perl",
                "-e",
                "while(<>){ eval or die $@; }"
            final Process p = Runtime.getRuntime().exec(cmd);
            new Thread(){
                public void run(){
                    try{
                        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
                        for(String line; (line = r.readLine()) != null; System.out.println("ProcessOUT:: "+line));
                    catch (Throwable t){
    //                    t.printStackTrace();
            }.start();
            new Thread(){
                public void run(){
                    try{
                        BufferedReader r = new BufferedReader(new InputStreamReader(p.getErrorStream()));
                        for(String line; (line = r.readLine()) != null; System.err.println("ProcessERR:: "+line));
                    catch (Throwable t){
    //                    t.printStackTrace();
            }.start();
            new Thread(){
                public void run(){
                    try{
                        OutputStream out = p.getOutputStream();
                        for(int ii = 0; ii < commands.length; ii++){
                            System.err.println("Sending command: "+commands[ii]);
                            out.write(commands[ii].getBytes());
                            out.write('\n');
                            out.flush();
                    catch (Throwable t){
    //                    t.printStackTrace();
            }.start();
            int exit = p.waitFor();
            System.err.println("Process exited with code: "+exit);
        static final String[]
            commands = {
                "print \"The road goes ever\\n\";",
                "print \"ever\\n\";",
                "print \"on.\\n\";",
                "exit 13;"
        ;

  • Perl in java

    hi guys
    is there is other way to call perl program in java without using exec command
    best regards

    Use could use JNI. You could even write a PERL interpreter in Java. I think using Runtime.exec is the best way, though (barring routes like "Don't use Java" or "Don't use PERL").

  • How to run Perl from Java

    Hi,
    I have a program written in Perl. I want to run the Perl program using Java. If there is a command which can allow me to call the perl program from Java program, please advise me.
    regards

    The most easy way is to use Runtime class to call "perl" to run your perl script.
    String sCmd = "c:\\yourPerlScriptLoc\\yourPerlScript.pl";
    Process p = Runtime.getRuntime().exec(sCmd);

  • Help with java translator...PLEASE!!!

    I am currently in the process of learning the JAVA language.
    i am having real problems tackling a question about programming a translator, can anyone help with this question?
    - Write a Java class 'German' to model the german dictionary(using only a few phrases, say 4-5). You will need to choose an appropriate representation for the constant dictionary(ignore accents etc), and to provide a method 'Translate' that, given an English phrase, returns the corresponding German phrase. You must also deal with phrases that are not available.
    I hope someone can help...
    John

    Learn a Map structure.

  • Migrating app from Perl to Java

    Hello all,
    I am fairly a newbie to Java and have been handed a new project, and I think Java is the proper way.
    The current application is written entirely in Perl and using Perl2Exe is an executable that is used internally at our company. What the tool does is, reads a CSV file, gathers IP/hostname, authentication information than connects (telnet and/or SSH and/or SNMP) to the said IP/Hosts (all cisco devices) and does a bunch (12 of them) of "cisco 'show'" commands and gathers the output into text files. One per IP/hostname. Which is then read in by another 3rd party application.
    I think I have a fair grasp of what needs to happen to convert the application into OO. The question is what libraries do I need to use for, since I don't want to reinvent the wheel
    - Reading CSV
    - Telnet
    - SSH v1 & v2
    - SNMP v1 v2c (possibly v3)
    Any help would be greatly appreciated. If at all possible, I would like to use GPL and/or Apache Licensed libraries.
    Thank you.
    awm
    P.S. In case you're asking why we're switching is that Perl on Windows doesn't really support SSH as a tty application and its not easily writable. Python is the other language of choice but I just would hate to have to switch to it, its just a pain to write in.

    I would say you can do this in Java no problem and there's lots of support for all the stuff you mentioned. Also, you can find everything you need at www.google.com. Once you start coding, post any problems/errors you have and we can provide more specific help.

  • Using perl Inline::Java and the BO SDK

    Hi, I'm looking for someone who's successfully used BO SDK though the Inline::Java perl module. I have only so far been able to connect to the CMS. I was hoping to see examples of report development, user management, server management, anything.
    Thank you,
    Mike

    Hi All heres the code with the propper tags i think, as for smorgasbords comment, I realise the security issue with java, but my lecturer seems to think its a good idea. Now the java applet opens a stream to my perl script and sends it parameters which the perl script uses to create the file. So java isnt making the file on any computer, perl is creating it on the server (EasyPHP actually). The example code given by my lecturer does actually work however for reasons which neither myself or the lecturer cannot see, it just doesnt create the file (or even open the perl script for that matter, as i used a file monitor to check if the 'diag.pl' file was accessed). I hope ive cleared up any questions.
    Thanks
    Dave
    void btnSendPosting_actionPerformed(ActionEvent e) { //Send Posting Event
    name = txtName.getText();
    email = txtEmail.getText();
    message = txtareaText.getText();
    path = txtFilePath.getText();
    String url = "http://localhost/cgi-bin/diag.pl";
    System.out.println("Url entered");
    try
    theURL = new URL(url);
    System.out.println("Url prepaired");
    catch (MalformedURLException f)
    System.out.println("Bad URL: " + theURL);
    try
    System.out.println("Beggining Connection...");
    URLConnection connection = theURL.openConnection();
    connection.setDoOutput(true);
    PrintWriter out = new PrintWriter(connection.getOutputStream());
    out.print("txtName="+name +"&txtEmail="+ email +"&txtMessage="+ message +"&txtPath="+path);
    out.close();
    System.out.println("End of Connection");
    catch (IOException f)
    System.out.println("Error Opening Connection");
    } //Send Posting Close bracket

  • Perl and java

    hi, does anyone know if you can get a string from a java applet and use it in perl.
    thanks

    There is no specific communication mechanism between applets and perl.
    To send data to a server-side perl script, you simply submit a form or send a GET request with the appropriate fields.

  • Using Perl From Java!

    Hi there, i have an assignment for university, part of it is to send data to a perl script through a Java applet. My perl script works, as i have tested it with a HTML form, however when i try it with java, i get nothing, nothing, no errors or warnings. Im using JBuilder6.
    I am convinced that there is a problem with my code and a connection is not being opened, my lecturer cant see what the problem is (im not too impressed!) so i come to you.
    All the perl does is create a file called test.txt and print within it the name, email..etc from the applet.
    Thanks in Advance, Dave Williams.
    JAVA:
    void btnSendPosting_actionPerformed(ActionEvent e) { //Send Posting Event
    name = txtName.getText();
    email = txtEmail.getText();
    message = txtareaText.getText();
    path = txtFilePath.getText();
    String url = "http://localhost/cgi-bin/diag.pl";
    System.out.println("Url entered");
    try
    theURL = new URL(url);
    System.out.println("Url prepaired");
    catch (MalformedURLException f)
    System.out.println("Bad URL: " + theURL);
    try
    System.out.println("Beggining Connection...");
    URLConnection connection = theURL.openConnection();
    connection.setDoOutput(true);
    PrintWriter out = new PrintWriter(connection.getOutputStream());
    out.print("txtName="+name +"&txtEmail="+ email +"&txtMessage="+ message +"&txtPath="+path);
    out.close();
    System.out.println("End of Connection");
    catch (IOException f)
    System.out.println("Error Opening Connection");
    } //Send Posting Close bracket

    Hi All heres the code with the propper tags i think, as for smorgasbords comment, I realise the security issue with java, but my lecturer seems to think its a good idea. Now the java applet opens a stream to my perl script and sends it parameters which the perl script uses to create the file. So java isnt making the file on any computer, perl is creating it on the server (EasyPHP actually). The example code given by my lecturer does actually work however for reasons which neither myself or the lecturer cannot see, it just doesnt create the file (or even open the perl script for that matter, as i used a file monitor to check if the 'diag.pl' file was accessed). I hope ive cleared up any questions.
    Thanks
    Dave
    void btnSendPosting_actionPerformed(ActionEvent e) { //Send Posting Event
    name = txtName.getText();
    email = txtEmail.getText();
    message = txtareaText.getText();
    path = txtFilePath.getText();
    String url = "http://localhost/cgi-bin/diag.pl";
    System.out.println("Url entered");
    try
    theURL = new URL(url);
    System.out.println("Url prepaired");
    catch (MalformedURLException f)
    System.out.println("Bad URL: " + theURL);
    try
    System.out.println("Beggining Connection...");
    URLConnection connection = theURL.openConnection();
    connection.setDoOutput(true);
    PrintWriter out = new PrintWriter(connection.getOutputStream());
    out.print("txtName="+name +"&txtEmail="+ email +"&txtMessage="+ message +"&txtPath="+path);
    out.close();
    System.out.println("End of Connection");
    catch (IOException f)
    System.out.println("Error Opening Connection");
    } //Send Posting Close bracket

  • Calling perl from java applets

    I have problems in executing PERL from a JAVA applet and Swing interface.
    I'm working under Windows 98.
    My aim is the following:
    When I click on the "Analizza" button,
    I want to execute a PERL program and automatically
    close the DOS window after completion. If there
    is an error, this error should be displayed in DOS.
    I wrote this piece of code
    public void actionPerformed(ActionEvent eventoUtente){
         String comandoPulsante = eventoUtente.getActionCommand();
              if (comandoPulsante == "Analizza"){
              Runtime rt = Runtime.getRuntime();
              try{
              Process pr= rt.exec("cmd -c c:\\command /c perl C:\\_webasco\\contatutto2.pl");
              catch(java.io.IOException ioEx)
              System.out.println("IOEx:"+ioEx.getMessage());
    I tried also with a Windows executable, ie I replaced the line
         Process pr= rt.exec("cmd -c c:\\command /c perl C:\\_webasco\\contatutto2.pl");
    with
         Process pr= rt.exec("command /c c:\\windows\notepad.exe");
    but in both cases nothing happens within the applet.
    What am I doing wrong????
    Any suggestions is warmly welcomed.
    Thank you
    Marina

    I know nothing about Perl, but the line
    if (comandoPulsante == "Analizza"){
    compares references not values and will always return false. Try:
    if (comandoPulsante.equals("Analizza")) {

  • Java translator

    Hi,
    i need a translator i can use in my java application to translate from italian to german? Any idea?

    I agree there is merit to the porting to Java but consider the following complexities of moving to Java in an automated fashion.
    C++ provides templates, structs, multiple inheritance, operator overloading, pass by reference and explicit destruction.
    Whilst Java provides none of these it does provide stronger RTTI, safe casting, a powerful encapsulation model through inner classes and a package hierarchy, dynamic class-loading and interfaces.
    I expect many here can suggest even more fundamental differences so treat my list as the tip of the iceberg.
    I'd seriously suggest rethinking the application and rewriting rather than trying to automate any kind of porting.
    Talden

Maybe you are looking for

  • How to extract the column width in ALv report if its executed in background

    I am executing an ALV report in background , in front end i am getting data properly, in back end for some columns some of the digits are missing.For example if PO no is of 10 digits it will display only 8 becos column size is like that , how to extr

  • COLOR/ BLACK AND WHITE PRESETS

    I am trying to set up a new computer to print both black and white and color. (I am working on two macs fyi) On my computer, I have the presets already made. On the new mac laptop, there are only Default and Last used. I figured out how to make prese

  • Max no of execute threads in 4.5

    Hi, We have set the no of execute threads in 4.5.1 to >700. During start up of the weblogic server, we get the following message: !!!!!!!!!!!!!!!!!!!!!Property weblogic.system.executeThreadCount has value: 775 > max: 400 setting value to 400 Does Web

  • Invalid coulmn index

    Im getting invalid coulmn index...any suggestions?...thanx in advance public static int[] getListSummary(UserDataVO userData) throws Exception { Connection connection     = null; PreparedStatement pstmt     = null; ResultSet resultSet          = null

  • Can we add Adobe Captivate 8 to our CC subscription?

    Hey everyone. I'm wanting to know if its possible to add Adobe Captivate 8 to my already existing CC monthly subscription. Is this possible?