Sign in to follow this  
Followers 0
mdwerne

Simultaneous FTP downloads code optimization

1 post in this topic

#1 ·  Posted (edited)

Hello,

I have some working code below that I'd like to optimize in two ways.

1) How can I open FTP connections simultaneously so that all the files I need (7 total) come down at once instead of one by one.

2) How can I declare the $ftp_file_mask variable from a list of names, instead of re-declaring it and calling Download() each time?

Any suggestions or pointers in the right direction would be appreciated.

Thanks,

-Mike

#include <GUIConstantsEx.au3>
#include <File.au3>
#include 'FTP.au3'

$server = 'ftp.symantec.com'
$username = 'anonymous'
$pass = 'pass'
$ftp_dir = '/public/english_us_canada/antivirus_definitions/symantec_antivirus_corp/'
$target_dir = @ScriptDir & "\Files\"
$ftp_file_mask = '*-v5i32.exe'
Download()
$ftp_file_mask = '*-v5i64.exe'
Download()
$ftp_file_mask = '*-i32.exe'
Download()
$ftp_file_mask = '*-i64.exe'
Download()
$ftp_dir = '/public/english_us_canada/antivirus_definitions/symantec_antivirus_corp/jdb/'
$ftp_file_mask = '*.jdb'
Download()
$ftp_dir = '/public/english_us_canada/antivirus_definitions/symantec_antivirus_corp/vdb/'
$ftp_file_mask = '*.vdb'
Download()
$ftp_dir = '/public/english_us_canada/antivirus_definitions/symantec_antivirus_corp/xdb/'
$ftp_file_mask = '*.xdb'
Download()

Func Download()
    
    $Open = _FTPOpen('MyFTP Control')
    If @error Then MsgBox(0, "ERROR", "Failed to open")
    $Conn = _FTPConnect($Open, $server, $username, $pass, 21)
    If @error Then MsgBox(0, "ERROR", "Failed to connect")

    Dim $Handle
    Dim $DllRect

    $FileInfo = _FtpFileFindFirst($Conn, $ftp_dir & $ftp_file_mask, $Handle, $DllRect)
    If $FileInfo[0] Then
        Do
            $dl_file = $FileInfo[10]
            $FileInfo = _FtpFileFindNext($Handle, $DllRect)

        Until Not $FileInfo[0]
    EndIf

    _FtpFileFindClose($Handle, $DllRect)

    _FTPClose($Open)

    $ftp_conn_string = "ftp://" & $username & ":" & $pass & "@" & $server & $ftp_dir & $dl_file

    InetGet($ftp_conn_string, $target_dir & $dl_file, 1, 1)

    While @InetGetActive
        Sleep(250)
    WEnd
EndFunc
Edited by mdwerne

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0