Hello
The script is not work any moor…
this is the error:
Exception calling "UploadFile" with "2" argument(s): "System error."
At C:\MMC\batch_graphe.ps1:917 char:6
+ $Xwebclient.UploadFile($Xuri, $XLocalFile)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
Thank for your help
Arnold
======================
$Xftp = " "
$XlocalDirectory = "c:\studio\"
$Xuser = " "
$Xpass = " "
$Xwebclient = New-Object System.Net.WebClient
$Xwebclient.Credentials = New-Object System.Net.NetworkCredential($Xuser,$Xpass)
$XFiles = Get-ChildItem -Path "c:\studio\*" -Rec -For | ? {$_.LastWriteTime -gt (Get-Date).AddHours(-1)} | where { ! $_.PSIsContainer } | Select-Object FullName
$Xnombre = $XFiles.Count
foreach ($XFile in $XFiles)
{
$XLocalFile = $XFile.FullName
$XRemoveDirectory = $XLocalFile.Replace("C:\studio\","")
$XChangeSlashes = $XRemoveDirectory.Replace('\', '/')
$XRemoveSpaces = $XChangeSlashes.Trim()
$XRemoteFile = $Xftp+$XRemoveSpaces
$Xuri = New-Object System.Uri($XRemoteFile)
$Xwebclient.UploadFile($Xuri, $XLocalFile)
Write-Host "Getting $XFile from $XlocalDirectory" -Foreground "Red" -BackgroundColor DarkBlue
Write-Host "Puting $XFile to $Xftp" -Foreground "Yellow" -BackgroundColor DarkBlue
}
""
Write-Host "Finished Sync to $Xftp" -Foreground "Green" -BackgroundColor DarkBlue
nitbha
June 30, 2019, 12:48pm
2
@Arnold
I have checked above script from my end and it is running as expected. As per error you have mention you need to make sure you are giving correct ftp path should be something like"ftp://{username}@{ftpa_address}{folder structure}"
Example:
“ftp://evilaosa@ftp.drivehq.com/drivehqshare/evilaosa/GroupWrite/”
Simple way to check the correct path using Filezilla.
Thank,
Nitesh Bhat
arnold
June 30, 2019, 3:28pm
3
Hello
Thanks for your reply
I no, this scripte works well!!
But i have to change the protocole to us “FTPES ”:
[Net.SecurityProtocolType]::Tls
Explicite
Passive
Porte 21
Thanks Arnold
<p style=“text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: ‘Segoe UI’, ‘Helvetica Neue’, ‘Apple Color Emoji’, ‘Segoe UI Emoji’, Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-weight: 400; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; font-variant-ligatures: normal; font-variant-caps: normal;”>you can try for below command in your script which enable the TLS security Connection for the session</p>
[Net.ServicePointManager]::SecurityProtocol =[Net.SecurityProtocolType]:: Ssl3 -bor[Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor[Net.SecurityProtocolType]::Tls12
<p style=“text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: ‘Segoe UI’, ‘Helvetica Neue’, ‘Apple Color Emoji’, ‘Segoe UI Emoji’, Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-weight: 400; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; font-variant-ligatures: normal; font-variant-caps: normal;”>Thanks,
Nitesh</p>
Or to be sure,
# enable all SSL protocols
[Net.ServicePointManager]::SecurityProtocol = 'Ssl3,Tls, Tls11, Tls12'
Thanks for your reply
I have this (no resultat)
cls
Set-ExecutionPolicy RemoteSigned
$errorActionPreference = 'SilentlyContinue'
$Xa = (Get-Host).UI.RawUI
$Xa.WindowTitle = "Sync Folder To Ftpes"
$Xftpes = "ftp://perso-ftp.orange/"
$Xftpes = [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls
$Xftpes = Get-Content "c:\studio\"
$XftpesW = "...……."
$XftpesP = "...……..."
$Xftpes = New-Object System.Net.WebClient
$Xftpes.ToString()
Also, divers Test:
cls
" 1"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls
Invoke-WebRequest "https://arenas.pagesperso-orange.fr/GradientExample/frameset-mediaplayer.html"
"=============================================="
" 2"
[Net.SecurityProtocolType]
" =============================================="
" 3"
# get TSL !!!
[enum]::GetNames([Net.SecurityProtocolType])
" =============================================="
" 4"
# Force PowerShell to use TLS 1.1
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls11
# ???
" ================================================= "
" 5"
# Force PowerShell to use it's default of TLS 1.0
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls
# ???
" ================================================= "
" 6"
# Force PowerShell ti use TLS 1.3
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls13
<#
Exception setting "SecurityProtocol": "Cannot convert null to type "System.Net.SecurityProtocolType" due to enumeration values that are not valid.
Specify one of the following enumeration values and try again. The possible enumeration values are "Ssl3,Tls,Tls11,Tls12"."
At C:\Users\admin\AppData\Local\Temp\f5d4da71-5524-47fe-8946-bb485ab4f8f6.ps1:26 char:1
+ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolTy ...
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting
#>
" ================================================ "
" 7"
[Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12
" ================================================ "
"8"
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3, Tls, Tls11, Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
$test = (Invoke-WebRequest -Uri "https://...........").StatusCode
$test
$AllProtocols
Thanks for your help
Arnold