PowerShell FTP Files

I am trying to move my files that I back nightly onto a local server to one of my hosted servers.  I have created this file in PowerShell script but am getting the below errors.  The server on the other end is 2K3 running FieZilla.

# locate all backup files
Foreach($File in Get-Childitem "\\ServerName\ServerBackups\SQL\db\" -recurse)
{
      # upload all the files
      
    $ftp = "ftp://username_backup:password@compass.mycompany.com/" + $File
    "ftp url: $ftp"

    $webclient = New-Object System.Net.WebClient
    $uri = New-Object System.Uri($ftp)

     "Uploading $File..."
      $webclient.UploadFile($uri, $File)
}

And here is the error I get

ftp url: ftp://username_backup:password@compass.mycompany.com/backup_201104081800.bak
Uploading backup_201104081800.bak...
Exception calling "UploadFile" with "2" argument(s): "An exception occurred during a WebClient request."
At line:13 char:23
+     $webclient.UploadFile <<<< ($uri, $File)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
 
ftp url:ftp://username_backup:password@compass.mycompany.com/backup_201104101800.bak
Uploading backup_201104101800.bak...
Exception calling "UploadFile" with "2" argument(s): "An exception occurred during a WebClient request."
At line:13 char:23
+     $webclient.UploadFile <<<< ($uri, $File)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
iaakadminAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexPaceCommented:
You could use the Task Scheduler to launch the Robo-FTP script below to accomplish the same goals.  This logic recurses into any subfolders and upload the files but does not recreate the directory structure.  This could be an issue if you have two subfolders containing files with the same name because one of them will be overwritten.  If you actually DO want to recreate the folder structure on the remote site just remove the /flat option on the SENDFILE command.
WORKINGDIR "\\ServerName\ServerBackups\SQL\db\"
IFERROR!= $ERROR_SUCCESS GOTO done  ; bail out if network path unreachable
FTPLOGON "ftp.mycompany.com" /user="backup" /pw="password@compass.mycompany.com"
SENDFILE "*.bak" /subdirs /flat  ; upload files in subfolders but not folders
FTPLOGOFF
:done
exit

Open in new window

Even if you don't want to do it with Robo-FTP you'll still need to consider how you want to handle the subfolders you recurse into and what will happen if multiple subfolders contain files with the same name.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Guy Hengel [angelIII / a3]Billing EngineerCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.