2017-05-04 16 views
0

私はサーバーのIPアドレスを持つファイルを持っています。そして、スクリプトはアドレスによってアドレス($line)を読み取るが、ダウンするサーバのアドレスが発生することがある。 IPアドレスの最後までスティールランをスクリプト化する必要があります。だから私は-Erroraction ContinueSet_FTPConnectionを使用しかし、とにかくスクリプトが壊れています。この問題を解決するには?FTPでファイルをアップロードする際にエラーが発生しました

foreach ($line in $FTPServer) 
    { 
     Start-Transcript -Path $results    
     Write-Host -Object "ftp url: $line" 
     Set-FTPConnection -Credentials $FTPCredential -Server $line -Session MySession -UsePassive -ErrorAction Continue 
     $Session = Get-FTPConnection -Session MySession 
     $Session>>.\sessions.txt 
     #Write-Host $Error[0] 
     if($session.UsePassive -eq "True"){$connect="OK"} 
     else{$connect="FAIL"} 

     foreach ($item in (Get-ChildItem .\Upload)) 
     { 
      #Get-FTPChildItem -Session $Session -Path /htdocs #-Recurse 
      Write-Host -Object "Uploading $item..." 
      $Send= Add-FTPItem -Session $Session -Path $FTPPlace -LocalPath .\Upload\$item -Overwrite -ErrorAction Continue #>> .\up.txt #.\Upload\test.txt 
      $item|gm >>.\up.txt 
      if($Send.Name -eq $item.Name){$Rec="OK"} 
      else{$Rec="!!!-FAIL-!!!"} 
      $array = $line, $item, $connect, $Rec 
      $FailTable=New-Object -TypeName PSObject -Property ([ordered]@{"FTP Server"=$array[0]; "File"=$array[1];"Connected"=$array[2];"Uploaded"=$array[3]}) 
      Add-Content .\stats.txt $FailTable 
     } 
     Stop-Transcript 
    } 

エラー:Test-NetConnectionの場合で

Start-Transcript : Transcription cannot be started. 
At F:\DPI FTP\FTPUpload_v2.ps1:21 char:9 
+   Start-Transcript -Path $results   #if $session.usepa ... 
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (:) [Start-Transcript], PSInvalidOperationException 
    + FullyQualifiedErrorId : CannotStartTranscription,Microsoft.PowerShell.Commands.StartTranscriptCommand 

ftp url: 10.80.59.173 
Test-NetConnection : The term 'Test-NetConnection' is not recognized as the name of a cmdlet, function, script file, or operable program. Ch 
eck the spelling of the name, or if a path was included, verify that the path is correct and try again. 
At F:\DPI FTP\FTPUpload_v2.ps1:23 char:13 
+   If (Test-NetConnection $line -Port '21') 
+    ~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : ObjectNotFound: (Test-NetConnection:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

Transcript started, output file is .\logs.txt 
ftp url: 10.80.59.170 
Test-NetConnection : The term 'Test-NetConnection' is not recognized as the name of a cmdlet, function, script file, or operable program. Ch 
eck the spelling of the name, or if a path was included, verify that the path is correct and try again. 
At F:\DPI FTP\FTPUpload_v2.ps1:23 char:13 
+   If (Test-NetConnection $line -Port '21') 
+    ~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : ObjectNotFound: (Test-NetConnection:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

と私のコードから

Transcript started, output file is .\logs.txt 
ftp url: 10.80.59.173 
Set-FTPConnection : Exception calling "GetResponse" with "0" argument(s): "Unable to connect to the remote server" 
At F:\DPI FTP\FTPUpload_v2.ps1:25 char:13 
+    Set-FTPConnection -Credentials $FTPCredential -Server $li ... 
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [Write-Error], WriteErrorException 
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Set-FTPConnection 

WARNING: Could not connect to 10.80.59.173 
Start-Transcript : Transcription cannot be started. 
At F:\DPI FTP\FTPUpload_v2.ps1:20 char:9 
+   Start-Transcript -Path $results   #if $session.usepa ... 
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (:) [Start-Transcript], PSInvalidOperationException 
    + FullyQualifiedErrorId : CannotStartTranscription,Microsoft.PowerShell.Commands.StartTranscriptCommand 


Stop-Transcript : An error occurred stopping transcription: The host is not currently transcribing. 
At F:\DPI FTP\FTPUpload_v2.ps1:47 char:9 
+   Stop-Transcript 
+   ~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (:) [Stop-Transcript], PSInvalidOperationException 
    + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.StopTranscriptCommand 
+0

質問を編集して、受け取ったエラーを含めることができますか? –

答えて

0

Continueが実際defauですlt設定。これは、終了していないエラーが発生した場合、エラーを表示してから、コマンドとスクリプトの残りの部分を続行しなければならないことを意味します。あなたはそれが役立つかどうかを確認するためにSilentlyContinueを試すことができます。

また、IPアドレスが最初に接続可能かどうかをテストすることもできます。あなたは、Windows 8/Server 2012の以降とPowerShellのV4を使用している+ではないあなたが(PINGのPSと等価である)の代わりにTest-Connectionを使用することができれば、あなたは、FTPポートのために特別にこれを行うにはTest-NetConnection -Port 21を使用することができた場合:

foreach ($line in $FTPServer) 
{ 
    Start-Transcript -Path $results    
    Write-Host -Object "ftp url: $line" 

    If (Test-Connection $line) { 

     Set-FTPConnection -Credentials $FTPCredential -Server $line -Session MySession -UsePassive -ErrorAction Continue 
     $Session = Get-FTPConnection -Session MySession 
     $Session>>.\sessions.txt 
     #Write-Host $Error[0] 
     if($session.UsePassive -eq "True"){$connect="OK"} 
     else{$connect="FAIL"} 

     foreach ($item in (Get-ChildItem .\Upload)) 
     { 
      #Get-FTPChildItem -Session $Session -Path /htdocs #-Recurse 
      Write-Host -Object "Uploading $item..." 
      $Send= Add-FTPItem -Session $Session -Path $FTPPlace -LocalPath .\Upload\$item -Overwrite -ErrorAction Continue #>> .\up.txt #.\Upload\test.txt 
      $item|gm >>.\up.txt 
      if($Send.Name -eq $item.Name){$Rec="OK"} 
      else{$Rec="!!!-FAIL-!!!"} 
      $array = $line, $item, $connect, $Rec 
      $FailTable=New-Object -TypeName PSObject -Property ([ordered]@{"FTP Server"=$array[0]; "File"=$array[1];"Connected"=$array[2];"Uploaded"=$array[3]}) 
      Add-Content .\stats.txt $FailTable 
     } 
     Stop-Transcript 

    } Else { 
     Write-Warning "Could not connect to $line" 
    } 
} 
+0

Windows 7を使用するときは?私はTest-NetConnectionをpingに置き換えました。問題は同じです。 – TraPS

+0

質問の内容をエラーの詳細で編集できますか? –

+0

私の答えを修正しました。 –

関連する問題