Saturday, 15 May 2010

ssh - java.io.FileNotFoundException: C:\Users\admin\Desktop\abcd (Access is denied) -


I am trying to transfer the directory to sftp remote server.

  import java.io .file; Import java.io.FileInputStream; Import com.jcraft.jsch.Channel; Import com.jcraft.jsch.ChannelSftp; Import com.jcraft.jsch.JSch; Import com.jcraft.jsch.Session; Public square FolderTransfer {public FolderTransfer () {} public static zero main (string [] args) {string SFTPHOST = "hostname"; Int Sftpf = 22; String SFTPUSER = "admin"; String SFTPPASS = "password"; String SFTPWORKINGDIR = "/ cygdrive / c / user / admin"; Session session = null; Channel channel = null; ChannelSftp Channel SFTP = Faucet; Try {JSch jsch = new JSch (); Session = JSCJet session (SFTPUSER, SFTPHST, SFTPAP); Session.setPassword (SFTPPASS); Java.util.Properties config = new java.util.Properties (); Config.put ("hardhostky checking", "no"); Session.setConfig (config); Session.connect (); Channel = session Open channel ("SFTP"); Channel.connect (); ChannelSftp = (ChannelSftp) channel; ChannelSftp.cd (SFTPWORKINGDIR); File f = new file ("C: \\ user \\ administrator \\ desktop \\ abcd \\"); ChannelSftp.put (new FileInputStream (f), f.getName ()); Println ("done ...."); } Hold (Exception pre) {ex.printStackTrace (); }}}  

But I'm getting an error like java.io.FileNotFoundException: C: \ Users \ Admin \ Desktop \ abcd (Access Denied) How can I solve it?

ABCD is not a file, it is a directory. Compress the directory and send it as a file or get all the files and send them one by one file file = new ("/ path"); File [] listOfFiles = folder.listFiles (); For (int i = 0; i


No comments:

Post a Comment