Hi Luc ,
this is in continuation of the last thread we discussed about vsphere best practices .
i need to put backup directory under ftp server using powershell
i want to put that piece of code in the main script .
however i am not able to connect ftp server using powershell
So we are on the same page, which OS are you doing this on?
And how did you set up the FTP server?
Is that with this script attached in Re: implemeting vsphere best practices and features_powercli
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes that he same script i attached .we discussed in last project thread about setting up the ftp server .
windows 2012 r2 is the os
i am giving backup location as
ftp://192.168.110.10:21/backup
though its in location path but do i need to give logic in script to create .
for some reasons working on ftp server works on comaand prompt not on powershell console .
With the following script I can upload a file to an FTP server.
The script will create the required folders (in $ftpPath) if they do not exist yet.
The name of the uploaded file can be changed with $ftpFile.
$ftpPath = 'Test/SubFolder'
$ftpFile = 'MyTest.txt'
$srcFile = 'C:\Test.txt'
$Username = "FTPUSER"
$Password = "VMware1!"
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($Username,$Password)
$pwd = ''
$ftpPath.Split('/') | ForEach-Object -Process {
try{
$pwd = "$pwd/$_"
$tPath = "ftp://$($ftpServer)$($pwd)"
$tDir = [System.Net.WebRequest]::Create($tPath)
$tDir.Credentials = New-Object System.Net.NetworkCredential($Username,$Password)
$tDir.Method = [System.Net.WebRequestMethods+FTP]::MakeDirectory
$tDir.GetResponse() | Out-File
}
catch [Net.WebException] {
try{
$cDir = [System.Net.WebRequest]::Create($tPath)
$cDir.Credentials = New-Object System.Net.NetworkCredential($Username,$Password)
$cDir.Method = [System.Net.WebRequestMethods+FTP]::PrintWorkingDirectory
$cDir.GetResponse() | Out-File
}
catch [Net.WebException] {
throw "Unknown error"
}
}
}
$uri = New-Object System.Uri("ftp://$ftpServer/$ftpPath/$ftpFile")
$webclient.UploadFile($uri,$srcFile)
$webclient.Dispose()
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thnaks Luc .iam going to check this .