10 Replies Latest reply on Oct 5, 2006 5:43 PM by 807607

    get file from secure ftp server

    807607
      Hi, i got a problem:
      i need to get a file thats generated every day at a certain time from a secure ftp server
      go thru it and fix one or two fields (file is in exact same format every time)
      and then upload it back to a different ftp server.

      does anyone have any tips on this subject?
      Thanks a lot
        • 1. Re: get file from secure ftp server
          807607
          Hi, i got a problem:
          i need to get a file thats generated every day at a
          certain time from a secure ftp server
          go thru it and fix one or two fields (file is in
          exact same format every time)
          and then upload it back to a different ftp server.

          does anyone have any tips on this subject?
          Thanks a lot
          What is your software for SSH anyway? I ask you this because you will need the commands SFTP2 (DOS) and SCP (Unix). I know that these commands will be embedded with Tectia SSH product, but not sure about the others.
          • 2. Re: get file from secure ftp server
            807607
            i havnt created the shell script yet, you are right it will be embedded so it will run at 7 pm daily., but the main problem isnt with the shell its with the retrieveing file from ftp (i got the url,username,pw)
            • 3. Re: get file from secure ftp server
              807607
              i havnt created the shell script yet, you are right
              it will be embedded so it will run at 7 pm daily.,
              but the main problem isnt with the shell its with the
              retrieveing file from ftp (i got the url,username,pw)
              This was a lovely post and all but had nothing at all to do with the questions the previous poster put to you. Have you found the client side secure FTP for Java software you will be using?
              • 4. Re: get file from secure ftp server
                807607
                i havnt created the shell script yet, you are right
                it will be embedded so it will run at 7 pm daily.,
                but the main problem isnt with the shell its with the
                retrieveing file from ftp (i got the url,username,pw)
                No, I don't think you are allowed to use password authentication on Secure Shell FTP, no matter it's via shell script or Java API.

                What you need to do first is to ask your System Admin to generate an encrypted key on the client and configure the profile to allow key authentication on the server.

                About your job schedule, I think you need a Job Scheduler software to handle that. My company is using CA-7 and AutoSys.

                By the way, I used to implemented SFTP like this
                Unix Server -> SFTP -> Java do something on Windows -> SFTP -> Print Server

                :D

                Message was edited by:
                TikkyChai
                • 5. Re: get file from secure ftp server
                  807607
                  Hi there. I had the exact same question.(How to connect using secure).

                  I have found a way to do it.
                  First of all, download jsch-0.1.28.zip
                  Can easily be found by just typing that into google.
                  Unzip the package and compile the code.(Under src\com\jcraft\jsch)
                  This gives you a very usefull Jar.
                  They also have examples in the folder.
                  Use the sftp example, include the newly created Jar and watch it work.
                  I have taken what I need from the sftp example and modified it to suit me.

                  Hope it helps and feel free to ask any more questions.

                  Kind Regards
                  Neil
                  • 6. Re: get file from secure ftp server
                    807607
                    Hi

                    Have you managed to get your program working?

                    Kind Regards
                    Neil
                    • 7. Re: get file from secure ftp server
                      807607
                      Hi TikkyChai

                      I think you are right.
                      Does it mean ' shell script which uses sftp to download file from remote server to local host ' , we need to do following.
                      1) Ask SA to generate key for my local m/c.
                      2) configure that key with userid (for my local m/c) on remote host.

                      3) Run sftp command using
                      sftp -oPort=<port> userid@ ServerHost
                      ---
                      blah...blah..
                      ---

                      Is there any other easy way to connect with remote server using sftp from shell script (without interactively asking password ) ?
                      I am open to shell script or Java process .
                      Pls. let me know ASAP.
                      Thanks in advance.
                      • 8. Re: get file from secure ftp server
                        807607
                        "I have taken what I need from the sftp example and modified it to suit me."

                        Can you post your modified code here? It seems not easy to modify the code without using swing... Thank you very much.
                        • 9. Re: get file from secure ftp server
                          807607
                          JSch jsch=new JSch();
                          //Set host- and user name.
                          username = "bla";
                          host = "000.000.000.000";
                          session = jsch.getSession(username, host, 22);
                          ui = new MyUserInfo();
                          session.setUserInfo(ui);
                          //Create the session.
                          session.connect();
                          channel = session.openChannel("sftp");
                          channel.setXForwarding(true);
                          //Connect to the site.
                          channel.connect();
                          c = (ChannelSftp)channel;
                          c.cd("newFile");
                          c.lcd("/oldFile/");
                          String p2=".";
                          SftpProgressMonitor monitor=new MyProgressMonitor();
                          int mode=ChannelSftp.OVERWRITE;
                          c.get("*.txt", p2, monitor, mode);

                          public static class MyUserInfo implements UserInfo {

                          public String getPassword(){ return passwd; }

                          public boolean promptYesNo(String str){
                          /*Object[] options={ "yes", "no" };
                          int foo=JOptionPane.showOptionDialog(null,
                          str,
                          "Warning",
                          JOptionPane.DEFAULT_OPTION,
                          JOptionPane.WARNING_MESSAGE,
                          null, options, options[0]);*/
                          int foo = 0;
                          return foo==0;
                          }
                          String passwd;

                          public String getPassphrase(){ return null; }

                          public boolean promptPassphrase(String message){ return true; }

                          public boolean promptPassword(String message){
                          passwd = "*******";
                          return true;
                          }

                          public void showMessage(String message){
                          //JOptionPane.showMessageDialog(null, message);
                          }


                          Here is how I edited the code. (Note, this is automated as I use it as a service on linux.)
                          • 10. Re: get file from secure ftp server
                            807607
                            Thank you.
                            Now I am getting the following error:

                            Exception in thread "DefaultQuartzScheduler_Worker-0" java.lang.NoClassDefFoundError: org/bouncycastle/crypto/params/DHKeyGenerationParameters
                                 at java.lang.Class.forName0(Native Method)
                                 at java.lang.Class.forName(Class.java:164)
                                 at com.jcraft.jsch.DHG1.init(Unknown Source)
                                 at com.jcraft.jsch.Session.receive_kexinit(Unknown Source)
                                 at com.jcraft.jsch.Session.connect(Unknown Source)
                                 at com.jcraft.jsch.Session.connect(Unknown Source)

                            Does anyone know how to solve the problem?