Creating powershell to upload file to FTP site RRS feed

  • Question

  • Hi,

    I am trying to creating powershell to upload MS access database file to a FTP server. I am new to PS, so I searched a few site and found

    I created one to test to upload txt file from my C:\Dir folder to FTP site.


    #we specify the directory where all files that we want to upload  
    #ftp server 
    $ftp = "" 
    $user = "username" 
    $pass = "password"  
    $webclient = New-Object System.Net.WebClient 
    $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)  

    foreach($item in (dir $Dir "*.txt")){ 
        "Uploading $item..." 
        $uri = New-Object System.Uri($ftp+$item.Name) 
        $webclient.UploadFile($uri, $item.FullName) 

    But I get the following output:

    PS C:\Users\username\Desktop> C:\Users\username\Desktop\powershell.ps1
    Uploading test.txt...
    Exception calling "UploadFile" with "2" argument(s): "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."
    At C:\Users\username\Desktop\powershell.ps1:17 char:26
    +     $webclient.UploadFile <<<< ($uri, $item.FullName) 
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    Could someone help on this? Thanks so much.

    Tuesday, December 10, 2013 3:03 AM

All replies

  • The error code 550 - UserName and Password Conflict

    Please try to add the code

    $ftp.KeepAlive = $false

    Regards Chen V [MCTS SharePoint 2010]

    Wednesday, December 11, 2013 9:33 AM