Index: wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmSvnExeWagonTest.java
===================================================================
--- wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmSvnExeWagonTest.java	(revision 897743)
+++ wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmSvnExeWagonTest.java	(working copy)
@@ -19,8 +19,14 @@
  * under the License.
  */
 
+import java.io.File;
+import java.io.IOException;
+
 import org.apache.maven.scm.provider.ScmProvider;
 import org.apache.maven.scm.provider.svn.svnexe.SvnExeScmProvider;
+import org.apache.maven.wagon.FileTestUtils;
+import org.apache.maven.wagon.Wagon;
+import org.codehaus.plexus.util.FileUtils;
 
 /**
  * Test for ScmWagon using SVN Exe as underlying SCM
@@ -36,5 +42,50 @@
     {
         return new SvnExeScmProvider();
     }
+    
+    public void testPutFileBasedirDoesNotExist()
+        throws Exception
+    {
+        setupRepositories();
 
+        setupWagonTestingFixtures();
+
+        Wagon wagon = (ScmWagon) getWagon();
+
+        sourceFile = new File( FileTestUtils.getTestOutputDir(), "directory-copy" );
+
+        sourceFile.mkdirs();
+        
+        writeTestFile( "test-resource-1.txt" );
+
+        wagon.connect( testRepository, getAuthInfo() );
+
+        wagon.putDirectory( sourceFile, "directory-copy" );
+        
+        wagon.putDirectory( sourceFile, "directory-copy/second-level-dir" );
+        
+        wagon.put( new File( sourceFile, "test-resource-1.txt" ), "directory-copy/test-resource-1.txt" );
+        
+        wagon.put( new File( sourceFile, "test-resource-1.txt" ), "directory-copy/second-level-dir/test-resource-1.txt" );
+
+        destFile = FileTestUtils.createUniqueFile( getName(), getName() );
+
+        destFile.deleteOnExit();
+        
+        wagon.get( "directory-copy/test-resource-1.txt", destFile );
+        
+        wagon.get( "directory-copy/second-level-dir/test-resource-1.txt", destFile );
+
+        wagon.disconnect();
+
+        tearDownWagonTestingFixtures();
+    }
+        
+    private void writeTestFile( String child )
+        throws IOException
+    {
+        File dir = new File( sourceFile, child );
+        dir.getParentFile().mkdirs();
+        FileUtils.fileWrite( dir.getAbsolutePath(), child );
+    }
 }
Index: wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java
===================================================================
--- wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java	(revision 897743)
+++ wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java	(working copy)
@@ -148,8 +148,6 @@
         {
             removeCheckoutDirectory();
         }
-
-        checkoutDirectory.mkdirs();
     }
 
     private File createCheckoutDirectory()
@@ -176,7 +174,7 @@
 
     private void removeCheckoutDirectory()
         throws ConnectionException
-    {
+    {   
         if( checkoutDirectory == null )
         {
             return; // Silently return.
@@ -255,7 +253,7 @@
         }
         putInternal( source, targetName );
     }
-
+    
     /**
      * Puts both files and directories
      *
@@ -284,13 +282,58 @@
             ScmProvider scmProvider = getScmProvider( scmRepository.getProvider() );
 
             String checkoutTargetName = source.isDirectory() ? targetName : getDirname( targetName );
-            String relPath = checkOut( scmProvider, scmRepository, checkoutTargetName, target );
+            
+            String relPath = "";
+            String missingDirs = "";
+            
+            try
+            {
+                relPath = checkOut( scmProvider, scmRepository, checkoutTargetName, target );
+            }
+            catch ( TransferFailedException te )
+            {                  
+                // recurse through the directories of the repository from the bottom up
+                // if directory does not exist, create it
+                String repoUrl = new String( getRepository().getUrl() );
 
+                try
+                {
+                    String baseRepoUrl = getBaseRepoUrl( repoUrl );
+                    scmRepository = null;
+                    scmProvider = null;
+
+                    scmRepository = getScmRepository( getRepository().getUrl() );
+
+                    scmProvider = getScmProvider( scmRepository.getProvider() );
+
+                    missingDirs = StringUtils.difference( baseRepoUrl, repoUrl );
+
+                    if ( checkoutDirectory != null )
+                    {
+                        try
+                        {
+                            removeCheckoutDirectory();
+                        }
+                        catch ( ConnectionException ce )
+                        {
+                            fireSessionDebug( "Unable to delete created checkout directory '" +
+                                checkoutDirectory.getPath() + "'." );
+                        }
+                    }
+
+                    relPath = checkOut( scmProvider, scmRepository, checkoutTargetName, target );
+                }
+                catch ( AuthorizationException ae )
+                {
+                    throw new ScmException( ae.getMessage() );
+                }
+            }           
+            
             File newCheckoutDirectory = new File( checkoutDirectory, relPath );
-
+            
             File scmFile =
-                new File( newCheckoutDirectory, source.isDirectory() ? "" : getFilename( targetName ) );
-
+                new File( newCheckoutDirectory, source.isDirectory() ? missingDirs : missingDirs + "/" + getFilename( targetName ) );
+            
             boolean fileAlreadyInScm = scmFile.exists();
 
             if ( !scmFile.equals( source ) )
@@ -307,9 +350,16 @@
 
             if ( !fileAlreadyInScm || scmFile.isDirectory() )
             {
+                String baseMissingDir = StringUtils.getChomp( missingDirs, "/" );
+                
+                if( baseMissingDir != null && !"".equals( baseMissingDir ) )
+                {
+                    scmFile = new File( newCheckoutDirectory, baseMissingDir );
+                }
+                
                 int addedFiles = addFiles( scmProvider, scmRepository, newCheckoutDirectory,
                                            source.isDirectory() ? "" : scmFile.getName() );
-
+                
                 if ( !fileAlreadyInScm && addedFiles == 0 )
                 {
                     throw new ScmException(
@@ -342,7 +392,30 @@
 
         firePutCompleted( target, source );
     }
+    
+    private String getBaseRepoUrl( String repoUrl )
+        throws NoSuchScmProviderException, ScmRepositoryException, AuthorizationException, TransferFailedException
+    {
+        repoUrl = StringUtils.chompLast( repoUrl, "/" );
 
+        String dir = StringUtils.getChomp( repoUrl, "/" );
+        String alteredRepoUrl = StringUtils.chomp( repoUrl, "/" );
+
+        getRepository().setUrl( alteredRepoUrl );
+
+        if ( resourceExists( dir ) )
+        {
+            getRepository().setUrl( alteredRepoUrl + dir );
+
+            return ( alteredRepoUrl + dir );
+        }
+        else
+        {
+            return getBaseRepoUrl( alteredRepoUrl );
+        }
+    }
+    
+    
     /**
      * Returns the relative path to targetName in the checkout dir. If the targetName already exists in the scm, this
      * will be the empty string.
@@ -356,9 +429,9 @@
     private String checkOut( ScmProvider scmProvider, ScmRepository scmRepository, String targetName,
                              Resource resource )
         throws TransferFailedException
-    {
+    {   
         checkoutDirectory = createCheckoutDirectory();
-
+        
         Stack stack = new Stack();
 
         String target = targetName;
@@ -401,7 +474,7 @@
             checkScmResult( ret );
         }
         catch ( ScmException e )
-        {
+        {   
             fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
             
             throw new TransferFailedException( "Error checking out: " + e.getMessage(), e );
@@ -456,7 +529,7 @@
         int addedFiles = 0;
 
         File scmFile = new File( basedir, scmFilePath );
-
+        
         if ( scmFilePath.length() != 0 )
         {
             AddScmResult result = scmProvider.add( scmRepository, new ScmFileSet( basedir, new File( scmFilePath ) ) );

