Results 1 to 6 of 6
  1. #1
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    74
    Rep Power
    0

    Default Copy folder from Local to Remote with JSch and the opposite

    Hello

    I would like to ask how i can create a bidirectional folder copy system with SFTP JSch is there any example. Like i see the code can only transfer file, I need to transfer a folder with mant files from my pc to a server and the opposite.


    Thank you in advanced
    ki_ha1984

  2. #2
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,843
    Rep Power
    5

    Default Re: Copy folder from Local to Remote with JSch and the opposite

    Yes, so that will be:

    - open session
    - create destination directory if it does not exist yet
    - for each (relevant) file in the source directory, upload it to the destination directory
    - close session

    And the other way around is the same code, but then you download rather than upload a file.

    If an example exists, you'll find it in the JSCH source download. But you only need an example of how to work with files and directories really, and based on your previous posts I do believe you already know how to do that:

    Redirect the setInputStream and the setOutputStream of the JSch
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    74
    Rep Power
    0

    Default Re: Copy folder from Local to Remote with JSch and the opposite

    Thank you very much.
    This means that i nees to list the content of a folder and to create a loop for transfering them one by one?

    ki_ha1984

  4. #4
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,843
    Rep Power
    5

    Default Re: Copy folder from Local to Remote with JSch and the opposite

    Yes indeed. And then comes the question which possibly makes this more challenging: do you also need to copy subdirectories?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    74
    Rep Power
    0

    Default Re: Copy folder from Local to Remote with JSch and the opposite

    yes i need to copy subdirectories end many. i think that i will have to create them i they not exist.
    Or is there any class that do this kind of things ?

  6. #6
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,843
    Rep Power
    5

    Default Re: Copy folder from Local to Remote with JSch and the opposite

    Well first try and get something working where you can create a directory where necessary and upload files to it. Being able to go through all subdirectories is going to be step 2.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Move remote file using JSCH
    By psilber in forum Advanced Java
    Replies: 1
    Last Post: 10-11-2012, 08:44 AM
  2. how to copy the files from fileserver to local path via browser?
    By mariaprabudass in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 12-12-2011, 04:00 PM
  3. Replies: 1
    Last Post: 03-05-2011, 05:47 PM
  4. copy file from local host to remote host
    By isotoper in forum New To Java
    Replies: 4
    Last Post: 12-24-2009, 04:41 PM
  5. Replies: 0
    Last Post: 01-22-2008, 11:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •