Downloading from multiple FTP's simultaneously.

  • Thread starter Thread starter X82
  • Start date Start date
I've managed to get all the data I need for the programme. If that is of any help. Again, all work is much, much appreciated.
 
Finally got to finish this off, was a fun challenge :D. Download: https://dl.dropbox.com/u/41110491/FTPDownload.zip (you'll need .NET framework 4 installed if you don't already)

Open Data\*.csv and fill in with your own addresses. Make sure you keep the same column names.

You can add other files if you want by adding them to the AndrewKiller.FTPDownload.GUI.exe.config file, e.g.:
Code:
<FTPFile>
  <Name>Saturday</Name>
  <Path>Data\Saturday.csv</Path>
</FTPFile>

Launch it, select your file (bottom-right) then hit 'Download' (bottom right) and see what happens :D.


Let me know if it works and I'll post up the full source-code :).

ftp1.png


ftp2.png


Remote downloads work too :o
 
Thats amazing work to put it mildly. I'm just about to test it now, but one thing. How do I add a username and password for the ftp? The username and password is the same for everyone. would I add this to the csv?

Again, this looks fantastic. Truly appreciate it.
 
I've been testing it this mornign and its amazing. It takes 60 seconds to do a task which took 60 minutes. However, there is one issue. It manages to download nearly all 444 items except about 9. Which say "The Remote server returned an error: (421) service not available, closing control connection". checking this IP manually shows no errors.
It's always the same 9. It's the last 8 in the list and one a few before. But as I said, manually going to this ftp in IE shows no issues. I've tried the download process 5 times and it produces the error every time. And always on the same IP's.

Apart from this, it works beautifully. Any ideas?

Update:

If I remove all the ip's from the CSV which download OK, then the programme will download about 7 of the ones it previously couldn't. however, there is still one IP which it refused to download even though I can download it myself through IE. An Odd one.

Update 2:

solved the issue. There was a couple of duplicate IP's in my list. Re-arranged the CSV and now it completes with no errors. Fantastic work.
Because I have such little experience with programming, how would I go about making changes to this? For example, removing the details window or adding a done notification sound and dialogue. Can you point me in the right direction with software etc? Very much appreciated, it works great.
 
Last edited:
Cool, sounds like a fair improvement then :D.

I imagine the servers for those duplicate FTP connections only allow one login per IP/user at once so when the downloader spawned multiple threads and connected to it twice at the same time they didn't like it.

All you need to modify it should be Visual Studio (as linked to above) but to be fair I doubt the downloader will be the easiest thing to understand straight away, though I was very anal about keeping the code very tidy and commented pretty much everything so you can get an idea about it. You can browse it online without having to download it and load it in Visual Studio here. FTPEngine.c is the core of the download system and Main.cs the GUI side for example.

If you want me to add a notification box on completion/sound I can if you like :).
 
Last edited:
I would love a few changes, but I feel guilty for asking these requests.
Heres my suggestions, feel free to disregard them.
I love how it looks now, with IP, rename to and status. I don't need save path shown. Would it also be possible to change "Rename To" to read "Reference".

As for notification etc, that would be a plus, but it takes such little time to complete I'm wondering if its worth it.

Perhaps a larger download button and drop down?

Sorry to be such a pain with all this. I feel a bit like a kid in a candy store!

One final query, is it possible to incorporate VBA scripts? The reason I ask is at the moment this programme downloads 440+ txt files. Then a seperate excel spreadsheet pulls certain figures from the text file and enter it in a spreadsheet. The VBA script is all written and works fine, but can it be used with this?

Again, sorry to be a pain. All your help so far has been fantastic.
 
Thank so you much for helping out like this. I will test it tomorrow at work and also post the vba code also. However, the link you have given appears to be broken. Any chance of a new one?
 
Here is the VBA code in question. There are 5 of these for each day.
It will take a certain value (there are 4 variations of the txt file) from each file and put it into a column in excel. I then match over the data myself manually. It's not an issue to get this incorporated into this programme, but would be amazing. Again, all help is appreciated!


Code:
Sub Moncom()
    Dim myDir As String, fn As String, txt As String
    Dim myMax As Double, myName As String, myLoc As String, n As Long
    Dim myMatch As Object, x, y, temp As String, i As Long, ii As Long
    myDir = "c:\Power Readings\Monday\"
    fn = Dir(myDir & "*.txt")
    If fn <> "" Then
        n = n + 1
        Sheets(1).Cells(n, 1).Resize(, 4).Value = _
        [{"FileName","Name","Location","Max"}]
        With CreateObject("VBScript.RegExp")
            .IgnoreCase = True
            Do While fn <> ""
                myName = Empty: myLoc = Empty: myMax = 0
                txt = CreateObject("Scripting.FileSystemObject") _
                .OpenTextFile(myDir & fn).ReadAll
                .Global = True
                .Pattern = "[^\n]+"
                Set myMatch = .Execute(txt)
                .Global = False
                For i = 0 To myMatch.Count - 1
                    .Pattern = "\b(I(out)?Max|Ph ?I(.A)?)(?=\t)"
                    If .test(myMatch(i)) Then
                        temp = .Execute(myMatch(i))(0)
                        x = Application.Match(temp, Split(myMatch(i), vbTab), 0)
                        myMax = Val(Split(myMatch(i + 1), vbTab)(x - 1))
                        Exit For
                    Else
                        .Pattern = "\b(IMax Ph1)(?=\t)"
                        If .test(myMatch(i)) Then
                            temp = .Execute(myMatch(i))(0)
                            x = Application.Match(temp, Split(myMatch(i), vbTab), 0)
                            For ii = x - 1 To x + 1
                                myMax = myMax + Val(Split(myMatch(i + 1), vbTab)(ii))
                            Next
                    Else
                        .Pattern = "\b(IMax B1)(?=\t)"
                        If .test(myMatch(i)) Then
                            temp = .Execute(myMatch(i))(0)
                            x = Application.Match(temp, Split(myMatch(i), vbTab), 0)
                            For ii = x - 1 To x
                                myMax = myMax + Val(Split(myMatch(i + 1), vbTab)(ii))
                            Next
                            Exit For
                            End If
                        End If
                    End If
                Next
                .Pattern = "(\d{2}(?:[/\.])){2}\d{4}\t(\d{2}:){2}\d{2}\t[^\t]+\t([^\t]+)\t([^\t]+)"
                If .test(txt) Then
                    myName = .Execute(txt)(0).submatches(2)
                    myLoc = .Execute(txt)(0).submatches(3)
                End If
                n = n + 1
                Sheets(1).Cells(n, 1).Resize(, 4).Value = _
                Array(fn, myName, myLoc, myMax)
                fn = Dir
            Loop
        End With
    Else
        MsgBox "No file found"
    End If
    
    MsgBox "Compiling Completed Successfully"
    
End Sub



Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub
 
Ahh OK. It's something which could be done, but It would take some deciphering from my-side to work out exactly what it's doing and convert it into C#. VB isn't the cleanest language to read :D.

If it's just as simple to run it as you currently do that may be easiest to be honest.

Demo'd this off to your bosses yet? :p
 
Sorry for the late response.
I agree, implementing this all in one would be too tricky when I can currently open excel and click a button. As it stands, it's working better than I hoped.
As most offices are full of some sort of politics, mine being no different, I am disappointed in the bosses responses to this. Lacklustre is one way to describe it. But I am more than happy that me and my 3 shift mate can complete a task which took us about 5 hours before, in 2 minutes. If I do find anything that needs modification, would it be ok to post here? Or would you rather I learn for myself?
 
lol, fortunately my manager is the exact opposite of that.

If you highlight how much time it saves, and then use this to calculate how much it saves the business I'm sure they'd be interested. Or just browse the internet for 4 hours 58 minutes and don't mention it :p.

And sure, as long as it doesn't take me days to do I'd look into it.
 
Back
Top Bottom