Upload files to an FTP Server by Poweshell

Theo: nguyenhaidang.name.vn | 15/06/2018 - 04:28

 

Description

Some days ago i had to upload some files to an FTP server. The files were sql server profiler traces and the size of every trace  was 300MB aprox. The internet connection wasn''t good at all and it took really long to upload a single file, so i decided to perform the task during the night, but of course i wasn''t willing to stay in front of the computer seeing how the files were uploaded or to upload the files by hand. So i made my own powershell script to solve the problem. The next morning all files were uploaded :).

Script

PowerShell
Edit Script
#we specify the directory where all files that we want to upload  
$Dir="C:/Dir"    
 
#ftp server 
$ftp = "ftp://ftp.server.com/dir/" 
$user = "user" 
$pass = "Pass"  
 
$webclient = New-Object System.Net.WebClient 
 
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)  
 
#list every sql server trace file 
foreach($item in (dir $Dir "*.trc")){ 
    "Uploading $item..." 
    $uri = New-Object System.Uri($ftp+$item.Name) 
    $webclient.UploadFile($uri$item.FullName) 
 } 
 

 

Back Head Print
Tin khác

Search GridView with Paging on TextBox KeyPress using jQuery in ASP.Net    (28/07/2010)

Bootstrap AutoComplete TextBox example using jQuery TypeAhead plugin in ASP.Net with C# and VB.Net    (28/07/2010)

Disable Button and Submit button after one click using JavaScript and jQuery    (29/07/2010)

Split and convert Comma Separated (Delimited) String to Table in SQL Server    (01/09/2010)

Select Column values as Comma Separated (Delimited) string in SQL Server using COALESCE    (01/09/2010)