Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

ftp upload subfolder content with powershell script... get trouble reading from subfolder

$
0
0

Hello All,
I'm trying to run a script that will get all the content of a folder (and its subfolder) to be uploaded to an fTP server.
I'll explain a bit the architecture of the folder:
The main folder name will always remain the same... Something like c:\test\
Inside c:\test\ there will be lots of random folders with numbers containing lots of .txt files.
They will be just numbers.
I'm trying to make a vbs that will copy ALL the files from the subfolders and upload them on an FTP (with no folders references).
So the structure on the client will be:
c:\test\1\a.txt, b.txt, c.txt
c:\test\2\a2.txt, b2.txt, c3.txt
......
The cOntent on the server will be:
\a.txt, a2.txt, b.txt, b2.txt, c.txt, c3.txt,...... *.txt 

#we specify the directory where all files that we want to upload 
cd  c:\test\
$files=Get-ChildItem -recurse

#ftp server
$ftp = <serverlocation>
$user = "aaa"
$pass = "aaa123" 
 
$webclient = New-Object System.Net.WebClient
 
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass) 
 
#list every sql server trace file
foreach($item in $files){
    "Uploading $item..."
    $uri = New-Object System.Uri($ftp+$item.Name)
    $webclient.UploadFile($item)}

I have an error stating this:

Cannot find an overload for "UploadFile" and the argument count: "1".
At C:\Users\Administrator\Desktop\testfirst.ps1:18 char:26
+     $webclient.UploadFile <<<< ($item)}
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

If for some reason the binary transfer will fail, we need to notify with an email...


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>