Hello,
I am trying to automate some upoads of files with FTPS in Powershell. I am using a script got from Internet, and changed a bit to my needs. But I am getting some errors when trying to test. I will copy the script and the error messages directly here. Maybe someone knows this errors and can help me in solving this ?
#FTP Multiple File Upload Script by Michael Reischl http://www.gamorz.de /-/ V.3
#Based on FTP Upload Script from http://www.thomasmaurer.ch
FTP Config
[Net.ServicePointManager]::ServerCertificateValidationCallback ={$true}
$Username = “Name” #FTP User
$Password = “Password” #FTP Password
$Dir = "\remotedir" #Local Folder
$RemotePath = “ftp://site/” #Ftp Server + Folder
#Start Loop to Upload every file in Local Folder, files can be filtered.
foreach($item in (dir $Dir))
{
Create FTP Request Object
$FTPRequest = [System.Net.FtpWebRequest]::Create(“$RemotePath$item”)
$FTPRequest = [System.Net.FtpWebRequest]$FTPRequest
$FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$FTPRequest.Credentials = new-object System.Net.NetworkCredential($Username, $Password)
$FTPRequest.UseBinary = $true
$FTPRequest.UsePassive = $false
$FTPRequest.Proxy = $NULL
$FTPRequest.EnableSSL = $true
Read the File for Upload
#$FileContent = gc -en byte $item.Fullname
$FTPRequest.ContentLength = $FileContent.Length
Get Stream Request by bytes
$Run = $FTPRequest.GetRequestStream()
$Run.Write($FileContent, 0, $FileContent.Length)
Cleanup
$Run.Close()
$Run.Dispose()
}
Exception calling “GetRequestStream” with “0” argument(s): "The remote server returned an error: (501) Syntax error i
n parameters or arguments."
At C:\DevelopedAddOns\FTPUpload3PL\Test\Untitled2.ps1:26 char:36
-
$Run = $FTPRequest.GetRequestStream <<<< ()
-
CategoryInfo      : NotSpecified: (
, MethodInvocationException -
FullyQualifiedErrorId : DotNetMethodException
You cannot call a method on a null-valued expression.
At C:\DevelopedAddOns\FTPUpload3PL\Test\Untitled2.ps1:27 char:11
-
$Run.Write <<<< ($FileContent, 0, $FileContent.Length)
-
CategoryInfo      : InvalidOperation: (Write:String) , RuntimeException
-
FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\DevelopedAddOns\FTPUpload3PL\Test\Untitled2.ps1:29 char:11
-
$Run.Close <<<< ()
-
CategoryInfo      : InvalidOperation: (Close:String) , RuntimeException
-
FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\DevelopedAddOns\FTPUpload3PL\Test\Untitled2.ps1:30 char:13
-
$Run.Dispose <<<< ()
-
CategoryInfo      : InvalidOperation: (Dispose:String) , RuntimeException
-
FullyQualifiedErrorId : InvokeMethodOnNull
Exception calling “GetRequestStream” with “0” argument(s): "The remote server returned an error: (501) Syntax error i
n parameters or arguments."
At C:\DevelopedAddOns\FTPUpload3PL\Test\Untitled2.ps1:26 char:36
-
$Run = $FTPRequest.GetRequestStream <<<< ()
-
CategoryInfo      : NotSpecified: (
, MethodInvocationException -
FullyQualifiedErrorId : DotNetMethodException
You cannot call a method on a null-valued expression.
At C:\DevelopedAddOns\FTPUpload3PL\Test\Untitled2.ps1:27 char:11
-
$Run.Write <<<< ($FileContent, 0, $FileContent.Length)
-
CategoryInfo      : InvalidOperation: (Write:String) , RuntimeException
-
FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\DevelopedAddOns\FTPUpload3PL\Test\Untitled2.ps1:29 char:11
-
$Run.Close <<<< ()
-
CategoryInfo      : InvalidOperation: (Close:String) , RuntimeException
-
FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\DevelopedAddOns\FTPUpload3PL\Test\Untitled2.ps1:30 char:13
-
$Run.Dispose <<<< ()
-
CategoryInfo      : InvalidOperation: (Dispose:String) , RuntimeException
-
FullyQualifiedErrorId : InvokeMethodOnNull