2017-05-04 2 views
0

서버의 IP 주소가있는 파일이 있습니다. 그리고 스크립트는 주소로 ($line) 주소를 읽지 만, 때로는 다운 될 서버의 주소가 발생할 수 있습니다. IP 주소의 끝까지 강철판을 쓴다. 그래서 나는 -Erroraction Continue to Set_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 
    } 

오류 : 내 코드

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 

에서의 경우와 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 

으로 :

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입니다 설정. 종료되지 않는 오류가 발생하면 오류를 표시 한 다음 명령과 나머지 스크립트를 계속 진행해야 함을 의미합니다. 도움이되는지 확인하려면 SilentlyContinue을 시도해보세요.

또는 IP 주소가 먼저 연결 가능한지 테스트 할 수 있습니다. 당신은 윈도우 8/서버 2012 이상 및 PowerShell을 V4를 사용하는 +하지 당신이 (핑의 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

그리고 Win 7을 사용할 때? 나는 Test-NetConnection을 ping으로 대체했고 문제는 동일합니다. – TraPS

+0

질문에 대한 자세한 내용을 편집 할 수 있습니까? –

+0

제 대답이 수정되었습니다. 도움이되는지 확인하십시오. –

관련 문제