How to upload using FTP in Powershell, behind a proxy?
Are you sure your proxy supports FTP, or is it HTTP only? See this thread:
FTP File Upload with HTTP Proxy
For WebClient I've used this in the past although it was for HTTP use, but you could give it a try:
$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")
Note that - "The UploadFile method sends a local file to a resource. This method uses the STOR command to upload an FTP resource. For an HTTP resource, the POST method is used."
I had the exception:
Exception calling "UploadFile" with "2" argument(s): "An exception occurred during a WebClient request."
Tracing showed, that when I used a ftp-uri and added a proxy to the webclient, no connections were initiated. (neither to server nor to proxy)
I am behind a ftp-proxy with authentication and the only way, it worked for me, was:
$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)