Many methods using PowerShell exist to upload a file in a remote server.
I am using the System.Net.WebClient
object to perform that task, and the Start-Process
command to do this in background.
My goal is to perform that task using only a one line command, via cmd.exe
.
The command below is used :
PowerShell.exe Start-Process -FilePath "PowerShell.exe" -ArgumentList "-c `"$uploadFile='PATH'; $linkFTP='ftp://user:pass@IP/file'; $client=New-Object -TypeName System.Net.WebClient; $URI=New-Object -TypeName System.Uri -ArgumentList $ftp; $client.UploadFile($URI,$uploadFile)`" "
This command ensures that via cmd.exe
, you will perform a FTP file upload in background using PowerShell. Using a script file directly instead of using -FilePath "PowerShell.exe" -ArgumentList "-c..."
will work, however with that method it will not.
You will notice if you run that command that it is certainly due to quotes problems.
Do you have any clue about it?
Thanks