-1

I am trying to copy a file from my local to ftp, using the following code.

$ftpname = ftp://xxx/xxx/file1.txt
$localfilepath = "C:\Outbox\file1.txt"
$ftpusername = "xxx"
$ftppassword = "xx"

$client = New-Object System.Net.WebClient
$client = New-Object System.Net.WebClient

$client.Credentials = New-Object System.Net.NetworkCredential($ftpusername,$ftppassword)

return $client.UploadFile($ftpname, $localfilepath)

I am getting "UploadFile" with "2" argument(s): "An exception occurred during a WebClient request."

I am well able to access the ftp in browser via same proxy settings. Is this something to do with proxy settings ?

wickjon
  • 900
  • 5
  • 14
  • 40

1 Answers1

0

Is the string that's being assigned to $ftpname missing quotes in your actual code, or just your example?

What you could try is changing

$ftpname = ftp://xxx/xxx/file1.txt

to this

$ftpname = New-Object System.Uri('ftp://xxx/xxx/file1.txt') 

The UploadFile() method has a few overloaded versions, one of which is UploadFile(URI, string). Would be interesting to see if it behaves differently. Other than that it could be network settings

campbell.rw
  • 1,366
  • 12
  • 22