locked
Upload PST files to FTP server RRS feed

  • Question

  • Hi Guys,

    I am trying to search the computer for .pst files and then upload them to a FTP server but I am running into issues.

    $ftp = "ftp://url/EXTERNALS/temp/"
    $user = "ftpuser"
    $pass = "passw"
    $files = $files=Get-ChildItem C:\ -recurse -File -Include '*.pst' -force -ErrorAction silentlycontinue 
    $webclient = New-Object System.Net.WebClient 
     
    $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)  
    foreach($item in $files){ 
        $uri = New-Object System.Uri($ftp+$item.Name) 
        $webclient.UploadFile($uri,$item.FullName)
    } 

    It gives me the following output in console

        Directory: C:\ProgramData\CanonBJ\IJPrinter\CNMWindows\Canon MG5100 series Printer
    
    
    Mode                LastWriteTime     Length Name                                                                                                            
    ----                -------------     ------ ----                                                                                                            
    -a---        31/12/2013     13:57       3180 archive.pst                                                                                                     
    
    
        Directory: C:\Users\All Users\CanonBJ\IJPrinter\CNMWindows\Canon MG5100 series Printer
    
    
    Mode                LastWriteTime     Length Name                                                                                                            
    ----                -------------     ------ ----                                                                                                            
    -a---        31/12/2013     13:57       3180 archive.pst                                                                                                     
    
    
        Directory: C:\Users\myuser\AppData\Local\Microsoft\Outlook
    
    
    Mode                LastWriteTime     Length Name                                                                                                            
    ----                -------------     ------ ----                                                                                                            
    -a---        06/01/2014     19:33  764158976 SharePoint Lists.pst                                                                                            
    Get-ChildItem : Access is denied
    At line:5 char:17
    + $files = $files=Get-ChildItem C:\ -recurse -File -Include '*.pst' -force -ErrorA ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Get-ChildItem], UnauthorizedAccessException
        + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetChildItemCommand

    The only file that gets uploaded is = Microsoft.Exchange.PST.dll

    Anyone has an idea?


    Monday, January 6, 2014 6:37 PM

Answers

  • This seems to work for me :)
    #we specify the directory where all files that we want to upload  
    $Files=get-childitem c:\ -recurse -force -ErrorAction silentlycontinue -Filter '*.pst'
     
     
    #ftp server 
    $ftp = "ftp://url/EXTERNALS/temp/" 
    $user = "user"
    $pass = "pw"
     
    $webclient = New-Object System.Net.WebClient 
     
    $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)  
     
    #list every sql server trace file 
    foreach($Item in $Files){ 
        "Uploading $item..." 
        $uri = New-Object System.Uri($ftp+$item.Name) 
        $webclient.UploadFile($uri, $item.FullName) 
     } 

    • Marked as answer by Bill_Stewart Tuesday, June 24, 2014 7:00 PM
    Monday, January 6, 2014 7:28 PM

All replies

  • No guarantees, but try fixing the line where you set the $files variable so that you are only setting it once. From this: $files = $files=Get-ChildItem... to $files = Get-ChildItem... If you still hit the error, then ensure that you do not have anything that is locking up the PST file, such as Outlook running. Also ensure that the account you are using to run the script (and used to open the shell) has access to the location and file.

    Monday, January 6, 2014 6:52 PM
  • Getting the following error. Nothing is blocking the files.

    User can access the location of the pst file.

    Get-ChildItem : Access is denied
    At line:5 char:8
    + $files=Get-ChildItem C:\ -recurse -File -Include '*.pst' -Exclude '*.dll*' -forc ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Get-ChildItem], UnauthorizedAccessException
        + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetChildItemCommand
     
    Exception calling "UploadFile" with "2" argument(s): "An exception occurred during a WebClient request."
    At line:11 char:5
    +     $webclient.UploadFile($uri,$item.FullName)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : WebException
     
    Exception calling "UploadFile" with "2" argument(s): "An exception occurred during a WebClient request."
    At line:11 char:5
    +     $webclient.UploadFile($uri,$item.FullName)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : WebException
     
    Exception calling "UploadFile" with "2" argument(s): "An exception occurred during a WebClient request."
    At line:11 char:5
    +     $webclient.UploadFile($uri,$item.FullName)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : WebException
     

    Monday, January 6, 2014 7:21 PM
  • This seems to work for me :)
    #we specify the directory where all files that we want to upload  
    $Files=get-childitem c:\ -recurse -force -ErrorAction silentlycontinue -Filter '*.pst'
     
     
    #ftp server 
    $ftp = "ftp://url/EXTERNALS/temp/" 
    $user = "user"
    $pass = "pw"
     
    $webclient = New-Object System.Net.WebClient 
     
    $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)  
     
    #list every sql server trace file 
    foreach($Item in $Files){ 
        "Uploading $item..." 
        $uri = New-Object System.Uri($ftp+$item.Name) 
        $webclient.UploadFile($uri, $item.FullName) 
     } 

    • Marked as answer by Bill_Stewart Tuesday, June 24, 2014 7:00 PM
    Monday, January 6, 2014 7:28 PM