[파워쉘] FTP 파일 업로드(file upload) 스크립트

2018. 12. 14. 14:59IT

파워쉘로 FTP를 이용하여  파일업로드를 할 케이스가 발생하였다.
어찌어찌하여 짜 본 스크립트다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#업로드 경로(전송할 파일 위치)
$Dir="D:/www/attend/"
  
#ftp정보
$ftp = "ftp://ftp주소/"
$user = "ftp아이디"
$pass = "ftp패스워드"
  
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
  
foreach($item in (dir $Dir "*.*")){
 "Uploading $item..."
 $uri = New-Object System.Uri($ftp+$item.Name)
 $webclient.UploadFile($uri, $item.FullName)
}