Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PowerShell
I am trying to run the following script and i get an error:
 
Exception calling "UploadFile" with "2" argument(s): "The remote server returned an error: (404) Not Found."
At C:\config\ftp1.ps1:16 char:22
+ $webclient.UploadFile <<<< ($uri, $item.FullName)
+ CategoryInfo : NotSpecified: (Smile | :) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
 
The script i am trying to run is :
$Dir = "c:\images\"
$ftp = "http://.............."
$user = "username"
$pass = "password"
 
"ftp url: $ftp"
 
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential ($user, $pass)
"Uploading $item..."
foreach($item in (dir $Dir "*.*")){
$uri = New-Object System.Uri($ftp+$item.Name)
 
"Uploading $item..."
 
$webclient.UploadFile($uri, $item.FullName)
}
 
"Upload Complete"
exit
 

 
Any ideas would be appreciated, i am pulling my hair out.
 
Thanks
Posted 4-Jan-13 2:03am
Edited 4-Jan-13 6:04am
(no name)5.1K
v2
Comments
Sergey Alexandrovich Kryukov at 4-Jan-13 8:07am
   
The Web page is not found, so what would you expect? Can you load it in some available browser? Upload manually from a browser?
—SA
paddy0388 at 5-Jan-13 16:40pm
   
I can see the page fine if i put the URL into a browser, And I can upload the files to it ok manually . Does it mean that the directory with the files that I am trying to upload is not found? or the page that the are going to isnt?
 
Thanks for your help
 
Paddy
Sergey Alexandrovich Kryukov at 5-Jan-13 20:08pm
   
It means that your URL points nowhere, to the resource which does not exist. Perhaps your URI is still wrong.
—SA
notjustme at 1-Mar-13 18:36pm
   
Perhaps this has been solved already but...
 
What does your $ftp variable actually end with? Like "somedomain.com", "somedomain.com/" or something else?
 
If it's the first one try adding the '/' to the ftp variable or inbetween "$ftp+$item.Name" when creating your URI-object.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 406
1 /\jmot 180
2 Suraj Sahoo | Coding Passion 170
3 Afzaal Ahmad Zeeshan 159
4 BillWoodruff 154
0 OriginalGriff 8,344
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,634
3 Maciej Los 5,024
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100