How to upload via FTP to Powershell, behind a proxy?

I am trying to use FTP in Powershell to upload a file. I use FtpWebRequestlater and then GetRequestStream, but this method returns an error:

"The requested FTP command is not supported when using the HTTP proxy."

I really am for the proxy and should be.

How can I load through Powershell when behind a proxy?

This will only be done with a .ps1Powershell script.

I also tried:

$webclient = New-Object System.Net.WebClient
$uri = New-Object System.Uri($server)

$webclient.UploadFile($uri, "C:\Test\1234567.txt")

Where $serverand this file are valid. But this code returns this error:

"An exception occurred during a WebClient request."
At C:\Test\script.ps1:101 char:26
+     $webclient.UploadFile <<<< ($uri, "C:\Test\1234567.txt")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

I also tried double backslash in files, didn't help.

The proxy I'm connected to applies only to HTTP, not FTP.

+5
source share
2 answers

, FTP, HTTP? :

FTP HTTP-

WebClient , HTTP, :

$wc = New-Object System.Net.WebClient
$wc.Headers.Add("User-Agent","Mozilla/4.0+")        
$wc.Proxy = [System.Net.WebRequest]::DefaultWebProxy
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$wc.UploadFile($uri, "C:\Test\1234567.txt")

, " UploadFile . STOR FTP-. HTTP POST."

+4

:

, "UploadFile" () "2": " WebClient".

, ftp-uri -, . ( , )

ftp- , , , :

$LocalFile = "C:\Temp\test.csv"
$FtpFile = "ftp://$ProxyUser:$ProxyPassword@$ProxyServer:21/ftp_test.csv"

$uri = New-Object System.Uri($FtpFile)
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential("$FtpUser@$FtpServer","$FtpPassword")
$webclient.UploadFile($uri, $LocalFile)
0

All Articles