Hallo Leute,
ich habe zwei PS Scripte für einen FTP Download u. Upload.
Download (ftp->local):
# Config $Username = "xxx" $Password = "xxxx" $ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path $LocalFile = "$ScriptDir\xxx.xml" $RemoteFile = "ftp://xxx-xxx.de/xxx/xxx.xml" # Create a FTPWebRequest $FTPRequest = [System.Net.FtpWebRequest]::Create($RemoteFile) $FTPRequest.Credentials = New-Object System.Net.NetworkCredential($Username,$Password) $FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile $FTPRequest.UseBinary = $true $FTPRequest.KeepAlive = $false # Send the ftp request $FTPResponse = $FTPRequest.GetResponse() # Get a download stream from the server response $ResponseStream = $FTPResponse.GetResponseStream() # Create the target file on the local system and the download buffer $LocalFileFile = New-Object IO.FileStream ($LocalFile,[IO.FileMode]::Create) [byte[]]$ReadBuffer = New-Object byte[] 1024 # Loop through the download do { $ReadLength = $ResponseStream.Read($ReadBuffer,0,1024) $LocalFileFile.Write($ReadBuffer,0,$ReadLength) } while ($ReadLength -ne 0)& "$ScriptDir\upload.ps1"
Upload(local->ftp):
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path $File = "$ScriptDir\xxx.xml" $ftp = "ftp://xxx:xxxxx@xxx.xxx.com/xxx.xml""ftp url: $ftp" $webclient = New-Object System.Net.WebClient $uri = New-Object System.Uri($ftp) "Uploading $File..." $webclient.UploadFile($Uri, $File)
Im Download Script versuche ich nach dem Download direkt das Upload Script zu starten:
& "$ScriptDir\upload.ps1"
Leider bekomme ich beim start des Upload Scripts immer folgende Fehlermeldung:
Ausnahme beim Aufrufen von "UploadFile" mit 2 Argument(en): "Ausnahmefehler während einer WebClient-Anforderung." Bei C:\Users\xxx\Desktop\xxxxx uploader\upload.ps1:12 Zeichen:22+ $webclient.UploadFile <<<< ($Uri, $File)+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException+ FullyQualifiedErrorId : DotNetMethodException
Wenn ich das Upload Script manuell in der Powershell starte, funktioniert alles!
Kann mir jemand sagen, was ich hier falsch mache?
Gruß
Michael