1. Simple script for uploading files to ftp
$username = "FTP_USER"
$password = "FTP_PASSWORD"
$localFile = "LOCAL_FILE_PATH"
$remoteFile = "ftp://SERVER_ADDRESS/" + "FILENAME"
# Create FTP Rquest
$request = [System.Net.FtpWebRequest]::Create("$remoteFile")
$request = [System.Net.FtpWebRequest]$request
$request.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$request.Credentials = new-object System.Net.NetworkCredential($username, $password)
$request.UseBinary = $true
$request.UsePassive = $true
# Read the File
$fileContent = gc -en byte $localFile
$request.ContentLength = $fileContent.Length
$run = $request.GetRequestStream()
$run.Write($fileContent, 0, $fileContent.Length)
# Close and dispose connection
$run.Close()
$run.Dispose()
No comments:
Post a Comment