Powershell 을 이용해 FTP Server를 상대로 자동화 작업을 하다보니 File 업로드, 다운로드 뿐 만 아니라. 특정 FTP 경로 아래에 있는 File 과 Directory 들의 정보가 필요 했다. 이때 FTP Server를 상대로 WebRequest를 보내는데 이때 Request Method를 “List”로 한다.
https://asperformance.com/uncategorized/giru4jp 이전에 올린 포스트인 Get-WebResponseString 을 이용하여 List를 요청 해 보자.
https://www.lcclub.co.uk/4xgs7em4nzahttps://worthcompare.com/xsnmy0ioac $Url = "ftp://Use-Powershell.com" $Username = "talsu" $Password = "pass1234" $credential = New-Object System.Net.NetworkCredential @($Username, $Password) Get-WebResponseString -Url $Url -Credential $credential -Method "List"
https://www.jamesramsden.com/2024/03/07/9k5htvpjh 다음과 같은 결과가 나온다. 내가 타겟으로 하고 있는 FTP Server는 Ubuntu에 설치 되어 있는 vsFTPd 이다. 만약 다른 FTP Server라면 출력 포멧이 다를 수도 있다.
https://musiciselementary.com/2024/03/07/rul6jprdrwxrwxrwx 10 1000 1000 4096 Jul 16 09:53 Storage -rw-r--r-- 1 1000 1000 179 Jun 16 21:19 examples.desktop drwx------ 2 1000 1000 4096 Jul 01 17:55 test drwxr-xr-x 2 1000 1000 4096 Jun 16 21:29 공개 drwxr-xr-x 2 1000 1000 4096 Jul 05 12:18 다운로드 drwxr-xr-x 2 1000 1000 4096 Jun 16 21:29 문서 drwxr-xr-x 2 1000 1000 4096 Jul 01 22:52 바탕화면 drwxr-xr-x 2 1000 1000 4096 Jun 16 21:29 비디오 drwxr-xr-x 3 1000 1000 4096 Jul 01 22:29 사진 drwxr-xr-x 2 1000 1000 4096 Jun 16 21:29 음악 drwxr-xr-x 2 1000 1000 4096 Jun 16 21:29 템플릿
https://musiciselementary.com/2024/03/07/qwsnc0yv524 이 출력은 하나의 문자열이다. 이것을 Parsing 해야 원하는 정보로 정렬하고 사용 할 수 있다. 다음은 FTP List를 Parsing 하는 Function 인데 추출하는 Regex는 자신의 Server와 다를수 있으니 알맞게 수정 하도록 하자.
https://fotballsonen.com/2024/03/07/a48q74qfmyxConvert-FtpList
Tramadol Tablets Online Function Convert-FtpList { param ([String]$ListString) $FileCache = [System.IO.Path]::GetTempFileName() Set-Content -Path $FileCache -Value $ListString $FTPListRegex = "(?
Order Tramadol Cod Online ([-r][-w][-xs]){3})s+(?
http://countocram.com/2024/03/07/cjo15973btz 임시 파일을 만들어 String을 File에 쓰고 Get-Content 의 출력을 Pipeline 으로 보내면 한줄씩 접근 할 수 있다. 한줄씩 접근 하기 위해 여러가지 방법이 있을 수 있지만 편한 방법으로 했다. (효율은 별로 좋지 못하다.)
https://giannifava.org/avplp8yq 한줄씩 접근하여 Regex로 값을 추출 해내고 그것을 Hash Table을 만든다. 이때 형 변환을 같이 하는데 DataTime 타입이 편리하게도 별다른 과정 없이 Parsing이 잘 되었다.
https://www.mominleggings.com/vztaz7vfac 최종 출력은 HashTable을 Property로 옮기는 Custom PSObject 들이다. 이것으로 원하는 정보로 정렬 작업을 할 수 있게 되었다.
https://www.goedkoopvliegen.nl/uncategorized/yc5auyuey
$Url = "ftp://Use-Powershell.com"
$Username = "talsu"
$Password = "pass1234"
$credential = New-Object System.Net.NetworkCredential @($Username, $Password)
$ListString = Get-WebResponseString -Url $Url -Credential $credential -Method "List"
Convert-FtpList $ListString
https://tankinz.com/x7fleda 출력은 다음과 같다. (Format-Table Type, LastWriteTime, Size, Name -AutoSize)
https://giannifava.org/skgz04h2s8p
Type LastWriteTime Size Name
---- ------------- ---- ----
Directory 2010-07-19 오후 4:21:00 4096 공개
Directory 2010-07-19 오전 5:12:00 4096 다운로드
Directory 2010-07-19 오후 4:21:00 4096 템플릿
Directory 2010-07-19 오후 4:21:00 4096 문서
Directory 2010-07-19 오전 1:22:00 4096 사진
Directory 2010-07-19 오후 4:21:00 4096 음악
Directory 2010-07-19 오전 1:22:00 4096 바탕화면
Directory 2010-07-19 오후 4:21:00 4096 비디오
Directory 2010-07-19 오후 4:09:00 4096 Storage
Directory 2010-07-19 오전 1:17:00 4096 test
File 2010-07-19 오후 4:21:00 179 examples.desktop
File 2010-07-19 오후 11:01:00 2964966 wordpress-3.0.zip
사용 예
https://www.jamesramsden.com/2024/03/07/j1dqasorgir 이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.