PowerShell - Upload files to multiple FTP sites

Ian

Administrator
Joined
Oct 27, 2013
Messages
1,735
Reaction score
630
I'm looking for a piece of software that would let me upload a set of files to multiple FTP sites at the same time - for example, when the forum software developers release a patch, I could upload them to the Windows 7/8/10 forums all at the same time.

My normal FTP client is FileZilla, but this doesn't have this feature. I did quite a bit of searching and the only other software I could find that does this is SmartFTP, but it was quite buggy when I tried it.

Has anyone seen any other software or method of uploading a set of files to multiple FTP sites?

edit: I've moved this to the PowerShell forum, as it's more a scripting query now
 
Last edited:

Regedit32

Moderator
Joined
Mar 4, 2016
Messages
3,609
Reaction score
1,140
Give PowerShell a go.

Code:
# This file contains the list of servers you want to copy files/folders to
$computers = gc "C:\scripts\servers.txt"
 
# This is the file/folder(s) you want to copy to the servers in the $computer variable
$source = "C:\Software\EMC\Networker\NWVSS.exe"
 
# The destination location you want the file/folder(s) to be copied to
$destination = "C$\temp\"
 
foreach ($computer in $computers) {
  if ((Test-Path -Path \\$computer\$destination)) {
    Copy-Item $source -Destination \\$computer\$destination -Recurse
  } else {
  "\\$computer\$destination is not reachable or does not exist"
  }
}

Credit: http://www.vsysad.com/2016/06/powershell-script-to-copy-file-to-multiple-remote-servers/
 

Ian

Administrator
Joined
Oct 27, 2013
Messages
1,735
Reaction score
630
Thanks @Regedit32 :)

I was hoping to use an app with a drag-and-drop interface, as the filenames change each time and I'll have quite a lot of files on occasion (thousands, in sub-folders etc...).

I think it's possible to get a drag and drop interface in PowerShell, so perhaps that is the way to go after all - I'll do some digging :).
 

Ian

Administrator
Joined
Oct 27, 2013
Messages
1,735
Reaction score
630
I've found a drag-and-drop script (http://www.rlvision.com/blog/a-drag-and-drop-gui-made-with-powershell/) and a recursive FTP upload script (https://gist.github.com/dkittell/f029b6c7d1c46ebcffcb) and both work well separately. So I should be able to combine them and get this working :D.

Good job we've got your tutorials, as I'm going to need to do some reading up! ;)

I figure that if I can set "$SrcEntries" from the FTP script using "$listBox.Items" from the drag-and-drop script, I should be a large way there. I can manually loop the FTP credentials, as they don't change as often as the files.
 

Regedit32

Moderator
Joined
Mar 4, 2016
Messages
3,609
Reaction score
1,140
Yes you should be able to incorporate drag n drop, plus you can also incorporate a progress bar too using a block of code around this:

Code:
 Write-Progress -Activity "Processing Files" -status "Processing File $Count / $TotalFiles" -PercentComplete ($Count / $TotalFiles * 100)
 

Regedit32

Moderator
Joined
Mar 4, 2016
Messages
3,609
Reaction score
1,140
I'll see what I can rustle together for you.

OR just post your progress and happy to return your favour to me, and be a second pair or eyes if you need help with any bugs :)
 

Regedit32

Moderator
Joined
Mar 4, 2016
Messages
3,609
Reaction score
1,140
In the mean time if you want to use a gui for now, search the forum for that guy whose name just dropped out of memory gggggrrrrr -- the one with the star trek name of that android --- I seem to recall him suggesting a few options when someone else asked about good ftp programs
 

Regedit32

Moderator
Joined
Mar 4, 2016
Messages
3,609
Reaction score
1,140
That guy with an eye for detail > would let you know if a single pixel in a 8 MB picture of snow, needed adjusting to improve the picture :D
 

Ian

Administrator
Joined
Oct 27, 2013
Messages
1,735
Reaction score
630
Thanks! I'll have a shot first and see how far I can get, as I've been meaning to learn PowerShell for quite some time, so it'll be an interesting learning exercise.

I'll report back here with my code as I make progress, so if you could take a look when I've got something to show, that would be very much appreciated :D.

Just so that the code will make sense, what I am aiming to code is the following (but I may skip a few features if it proves complex):
  • As for an input of domain names (i.e. windows10forums.com, w7forums.com), usernames and passwords in this format (as I can copy/paste as required):
    Code:
    domain.com, username, password
    domain2.com, username2, password2
    domain3.com, username3, password3
  • Listbox where I can drag and drop files/folders
  • FTP feature will copy and overwrite all of those files to all of the FTP domains entered (including directory contents to all levels)
  • Any errors are listed in an on-screen log, along with a progress bar of file transfers
I think I could create that without drag-and-drop easily enough, so that should be where the hard part is!

-- the one with the star trek name of that android ---

Data - got it :D.
 

Regedit32

Moderator
Joined
Mar 4, 2016
Messages
3,609
Reaction score
1,140
Actually the drag and drop will be the easier bit imo.

If you want to have drag and drop look at the [System.Reflection.Assembly] in PowerShell

I can rustle together a short tutorial on that if you like
 

Ian

Administrator
Joined
Oct 27, 2013
Messages
1,735
Reaction score
630
That would be fantastic if you've got time!

This script should make it so much easier to patch the sites when updates come out :D.
 

Regedit32

Moderator
Joined
Mar 4, 2016
Messages
3,609
Reaction score
1,140
When you get it working as you want it to you'll have to submit it to Github or Microsoft's PowerShell Gallery.

Pretty sure others would love a decent script.
 

Ian

Administrator
Joined
Oct 27, 2013
Messages
1,735
Reaction score
630
Yep, I'll stick it on GitHub, as I need to get my head around that too - so it's a perfect test :).
 

Ian

Administrator
Joined
Oct 27, 2013
Messages
1,735
Reaction score
630
I think it is dawning on me just how brilliant PowerShell is...

I've made a CSV of the domains (name, ftp address, username) and to import it in to an array, it's as simple as using:

Code:
$domains = Import-Csv "domains.csv"

I still have a long, long way to go - but I'm learning a lot :D.
 

Regedit32

Moderator
Joined
Mar 4, 2016
Messages
3,609
Reaction score
1,140
Nice one :cool:

I'm preparing the drag and drop tutorial, but before I carry on with this, I wanted to know how far down the rabbit hole you want to go with that.

It's easy enough to create a basic form you drag files to that become part of a [array] $List, but are you wanting that same form to have a panel that acts like File explorer so you don'y have to handle File Explorer in one view and the form in another view?
 
Joined
May 6, 2015
Messages
2,848
Reaction score
501
I minor joy of being retired and no long a software developer is that one does not have to learn any scripting tools like Powershell! One can just be a dumb user...with no need to update many things at once. I did once upon a time spend at least two evenings a week compiling a whole suite of stuff, testing it and then with scripts updating 8-10 machines before bedtime. Not windows, not even MS-Dos, much cruder than either!
 

Regedit32

Moderator
Joined
Mar 4, 2016
Messages
3,609
Reaction score
1,140
I minor joy of being retired and no long a software developer is that one does not have to learn any scripting tools like Powershell! One can just be a dumb user

I'll stop programming and Scripting when the coffee no longer exists :D

But I still have to Amen your thought LoL - I do at times wonder why bother myself.

I guess these days its more about fun, a challenge occasionally, and a time filler given I cannot relax by watching tv
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top