This question is related to the following answer posted by Zon.     I used the following code to copy a folder from remote to local.  public void downloadDir(String sourcePath, String destPath) throws SftpException { // With subfolders and all files.     // Create local folders if absent.     try {         new File(destPath).mkdirs();     } catch (Exception e) {         System.out.println("Error at : " + destPath);     }     sftpChannel.lcd(destPath);      // Copy remote folders one by one.     lsFolderCopy(sourcePath, destPath); // Separated because loops itself inside for subfolders. }  private void lsFolderCopy(String sourcePath, String destPath) throws SftpException { // List source (remote, sftp) directory and create a local copy of it - method for every single directory.     Vector&lt;ChannelSftp.LsEntry&gt; list = sftpChannel.ls(sourcePath); // List source directory structure.     for (ChannelSftp.LsEntry oListItem : list) { // Iterate objects in the list to get file/folder names.         if (!oListItem.getAttrs().isDir()) { // If it is a file (not a directory).             if (!(new File(destPath + "/" + oListItem.getFilename())).exists() || (oListItem.getAttrs().getMTime() &gt; Long.valueOf(new File(destPath + "/" + oListItem.getFilename()).lastModified() / (long) 1000).intValue())) { // Download only if changed later.                 new File(destPath + "/" + oListItem.getFilename());                 sftpChannel.get(sourcePath + "/" + oListItem.getFilename(), destPath + "/" + oListItem.getFilename()); // Grab file from source ([source filename], [destination filename]).             }         } else if (!".".equals(oListItem.getFilename() || "..".equals(oListItem.getFilename())) {             new File(destPath + "/" + oListItem.getFilename()).mkdirs(); // Empty folder copy.             lsFolderCopy(sourcePath + "/" + oListItem.getFilename(), destPath + "/" + oListItem.getFilename()); // Enter found folder on server to read its contents and create locally.         }     } }   But I am getting a null pointer exception at the following line which I am unable to resolve.  Vector&lt;ChannelSftp.LsEntry&gt; list = sftpChannel.ls(sourcePath); // List source directory structure   I get that it has problem reading the source path but why? Please suggest.  Edited:  This is the stacktrace:  Exception in thread "main" 4:      at com.jcraft.jsch.ChannelSftp.ls(ChannelSftp.java:1720)     at com.jcraft.jsch.ChannelSftp.ls(ChannelSftp.java:1526)     at org.gradle.CopyTest.downloadDir(CopyTest.java:68)     at org.gradle.CopyTest.main(CopyTest.java:97) Caused by: java.lang.NullPointerException     at com.jcraft.jsch.ChannelSftp.ls(ChannelSftp.java:1543)     ... 3 more   This exception is getting thrown:           throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);   From this statement I believe:  ((MyPipedInputStream)io_in).updateReadSide();
129
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
97068
I have an external hard drive with many files (800 GB). I want to copy the entire contents of the external hard drive to my local drive. get many errors about long file name or long file path. Renaming is also not possible because of number of errors.  What can I do about this issue?
53704
What I am doing is converting mp3's with LAME. I already have an old script I wrote that works but I want to add to it this ability--to no longer delete the file but instead save it in a new root folder with sub-directories that match the using the path that it is already in.  This is the code I got off the Internet that I am using in my script to get the path:   c=$FILENAME  xpath=${c%/*}   xbase=${c##*/}  xfext=${xbase##*.}  xpref=${xbase%.*}  path=${xpath}  pref=${xpref}  ext=${xfext}   The xpath and path give me the directory structure /home/user/working-root-directory/band-folder/album-name/  Using that technique, how do I script this to get just the band-folder into a separate variable and the album-folder into a separate variable?  Then I can use them to create  new folders keeping all the mp3s in band album order to put them into a different root folder; this would eliminate me from having to move them myself so the next time I run my script I will not re-sample them again because they will no longer be in the working directoy path/folders and still have a back up copy of my files just in case.
54742
In my terminal shell, I ssh'ed into a remote server, and I cd to the directory I want.   Now in this directory, there is a file called table that I want to copy to my local machine /home/me/Desktop.   How can I do this?  I tried scp table /home/me/Desktop but it gave an error about no such file or directory.   Does anyone know how to do this?
18864
Is there any way other than looping through the Files to check whether the folder or files exist in document library using clientcontext - client object model..  Can someone confirm me whether the below code will work or not. Or will it create any exception??  using(var clientContext = new ClientContext(site))  {  Web web = clientContext.Web;  Microsoft.SharePoint.Client.File file = web.GetFileByServerRelativeUrl("/site/doclib/folder/filename.ext");  bool bExists = false;  try { clientContext.Load(file);  clientContext.ExecuteQuery();   bExists = file.Exists;  } catch{ }  if (bExists ) { . .  }
101639
How can I copy the path to a folder or a file? The Info Dialog doesn't allow me to copy the information that stands there ...    Is there an easy way to do this?
65948
I am trying to copy a file over from a mapped drive on a network to the current computer through a batch file.   I've already attempted the following below and still no results. The plan is to run a batch file to copy a file from a network drive down to the local C:\ drive.   @echo off copy H:\Videos\TargetVideo\TargetVideo.mp4 C:\Video\
94433
I'm writing an app that supposed to copy a bunch of files from one place to another. When I'm using TFileStream for the copy it is 3-4 times slower than copying the files with the OS.  I also tried to copy with a buffer, but that was too slow aswell.  I'm working under Win32, anyone got some insights on this matter?
51748
I'm currently using Win32ShellFolderManager2 and ShellFolder.getLinkLocation to resolve windows shortcuts in Java. Unfortunately, if the Java program is running as a service under Vista, getLinkLocation, this does not work. Specifically, I get an exception stating "Could not get shell folder ID list".  Searching the web does turn up mentions of this error message, but always in connection with JFileChooser. I'm not using JFileChooser, I just need to resolve a .lnk file to its destination.  Does anyone know of a 3rd-party parser for .lnk files written in Java I could use?  I've since found unofficial documentation for the .lnk format , but I'd rather not have to do the work if anyone has done it before, since the format is rather scary.
108731
I want to copy a file from A to B in C#. How do I do that?
42885
I am trying to copy a folder to remote Ubuntu server using command line ssh connection, i understand it's doable to transfer a file using scp but i have many files in a folder iam trying to copy to that remote server, how is that done? anyone?  Thank you.
70238
In the upcoming Java7, there is a  to check if two file object are same file reference.  Are there similar API provided in the .NET framework?  I've search it over MSDN but nothing enlighten me.  I want it simple but I don't want to compare by filename which will cause problems with hard/symbolic links and different style of path. (e.g. \\?\C:\, C:\).   What I going to do is just prevent duplicated file being drag and dropped to my linklist.
36085
reveals that one can copy all files - including hidden ones - from directory src into directory dest like so:  mkdir dest cp -r src/. dest   There is no explanation in the answer or its comments as to why this actually works, and nobody seems to find documentation on this either.  I tried out a few things. First, the normal case:  $ mkdir src src/src_dir dest &amp;&amp; touch src/src_file src/.dotfile dest/dest_file $ cp -r src dest $ ls -A dest dest_file  src   Then, with /. at the end:  $ mkdir src src/src_dir dest &amp;&amp; touch src/src_file src/.dotfile dest/dest_file $ cp -r src/. dest $ ls -A dest dest_file  .dotfile  src_dir  src_file   So, this behaves simlarly to *, but also copies hidden files.  $ mkdir src src/src_dir dest &amp;&amp; touch src/src_file src/.dotfile dest/dest_file $ cp -r src/* dest $ ls -A dest dest_file  src_dir  src_file   . and .. are proper hard-links as , just like the directory entry itself.  Where does this behaviour come from, and where is it documented?
37131
I don't know if it's legit at StackOverflow to post your own answer to a question, but I saw nobody had asked this already.  I went looking for a C# Glob and didn't find one, so I wrote one that others might find useful.
121221
I have a web server that I want to map a drive to it. I want to do this in a .bat file. Pseudo ->   Check if a drive at an ip address has been mapped to a local drive.  If it has then progress with a reference to the drive If not map to a local drive and then progress with a reference to the drive  Is this possible and if so how can I achieve it?
82805
I'm working on a simple tool that transfers files to a hard-coded location with the password also hard-coded.  I'm a python novice, but thanks to ftplib, it was easy:  import ftplib  info= ('someuser', 'password')    #hard-coded  def putfile(file, site, dir, user=(), verbose=True):     """     upload a file by ftp to a site/directory     login hard-coded, binary transfer     """     if verbose: print 'Uploading', file     local = open(file, 'rb')         remote = ftplib.FTP(site)        remote.login(*user)              remote.cwd(dir)     remote.storbinary('STOR ' + file, local, 1024)     remote.quit()     local.close()     if verbose: print 'Upload done.'  if __name__ == '__main__':     site = 'somewhere.com'            #hard-coded     dir = './uploads/'                #hard-coded     import sys, getpass     putfile(sys.argv[1], site, dir, user=info)   The problem is that I can't find any library that supports sFTP.  What's the normal way to do something like this securely?    Edit:  Thanks to the answers here, I've gotten it working with Paramiko and this was the syntax.  import paramiko  host = "THEHOST.com"                    #hard-coded port = 22 transport = paramiko.Transport((host, port))  password = "THEPASSWORD"                #hard-coded username = "THEUSERNAME"                #hard-coded transport.connect(username = username, password = password)  sftp = paramiko.SFTPClient.from_transport(transport)  import sys path = './THETARGETDIRECTORY/' + sys.argv[1]    #hard-coded localpath = sys.argv[1] sftp.put(localpath, path)  sftp.close() transport.close() print 'Upload done.'   Thanks again!
104493
I have Library on which I have created a ribbon button. On click of the button I am trying to identify if the selected item is a folder or a file. below if the code snippet that I am using:  var context = SP.ClientContext.get_current(); var web = context.get_web();  var items = SP.ListOperation.Selection.getSelectedItems(context);  var currentLibrary = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList(context));  var index; for (index in items) {     var selectedItem = currentLibrary.getItemById(items[index].id);     // Need to identify if 'selectedItem' is folder or not     console.log("FileSystemObjectType = " + selectedItem.FileSystemObjectType); // Returns 'undefined'     console.log("get_file = " + selectedItem.get_file()); // Returns 'SP.ListItem' object     console.log("get_folder = " + selectedItem.get_folder()); // Returns 'SP.ListItem' object }   Taking reference from  I tried to use FileSystemObjectType but in my case it ends up showing undefined for both file and folder. Also if I try to check if the selected item is a file or folder using below code it always return true.  if(item.FileSystemObjectType == SP.FileSystemObjectType.Folder) {     // Always returns true }   What am I doing wrong here? How can I identify if the selected item in Library is a file or a folder?