Jump to content

FTP - File Transfer Protocol client


Wade
 Share

Recommended Posts

I need a very basic Autoit FTP client that I can integrate into an auto-update application I'm working on. I have done a lot of Telnet user-invisible scripts in the past, so this is very similar. All I need to do is be able to read an FTP directory (to see if a new file version is available), but a separate data port has to be set up to do that (more work than a regular telnet session). I can't just connect to the port 21, log in, and pull a directory listing by sending "LIST".

Rather than re-invent the wheel, I'm hoping someone on here has already accomplished this. The problem is that I can't find anything about on this Forum it because the Search function won't do a search with "FTP" in the title because it is only 3 characters long.

Any help is appreciated!

Thanks,

Wade

Link to comment
Share on other sites

I need a very basic Autoit FTP client that I can integrate into an auto-update application I'm working on. I have done a lot of Telnet user-invisible scripts in the past, so this is very similar. All I need to do is be able to read an FTP directory (to see if a new file version is available), but a separate data port has to be set up to do that (more work than a regular telnet session). I can't just connect to the port 21, log in, and pull a directory listing by sending "LIST".

Rather than re-invent the wheel, I'm hoping someone on here has already accomplished this. The problem is that I can't find anything about on this Forum it because the Search function won't do a search with "FTP" in the title because it is only 3 characters long.

Any help is appreciated!

Thanks,

Wade

The function below returns a 2-dimensional array. first dimension is a string of all the directories, second is string listing all the files. The separator is #.

Hope it makes sense.

Func FTPListFilesmg($l_FTPSession, $s_RemotePath,$l_Flags = 0, $l_Context = 0)
    Dim $ret[2]
    #cs
        typedef struct _WIN32_FIND_DATA {
        DWORD dwFileAttributes;
        FILETIME ftCreationTime;
        FILETIME ftLastAccessTime;
        FILETIME ftLastWriteTime;
        DWORD nFileSizeHigh;
        DWORD nFileSizeLow;
        DWORD dwReserved0;
        DWORD dwReserved1;
        TCHAR cFileName[MAX_PATH];
        TCHAR cAlternateFileName[14];
        }
        
    #ce
    $str = "dword;int[2];int[2];int[2];dword;dword;dword;dword;char[256];char[14]"
    $WIN32_FIND_DATA = DllStructCreate($str)
    $fd= DLLStructCreate($FILETIME)
;msgbox(0,'','List1')
    Local $callFindFirst = DllCall('wininet.dll', 'int', 'FtpFindFirstFile', 'long', $l_FTPSession, 'str',$s_RemotePath, 'ptr', DllStructGetPtr($WIN32_FIND_DATA), 'long', $l_Flags, 'long', $l_Context)
;msgbox(0,'',$callFindFirst[0])
    If Not $callFindFirst[0] Then
        MsgBox(0, "Folder Empty", "No Files Found ")
        SetError(-1)
        Return 0
    EndIf
    $ret[0] = ""
    $ret[1] = ""
    While 1
        $date = ''

        If DllStructGetData($WIN32_FIND_DATA, 1) <> 16 Then;if not a directory
            
            DllStructSetData($fd, 1, DLLStructGetData($WIN32_FIND_DATA, 4,1))
            DllStructSetData($fd, 2, DLLStructGetData($WIN32_FIND_DATA, 4,2))
            $datetime = _FileTimeToSystemTime($fd)
            $iMonth  = DllStructGetData($datetime, $ST_MONTH)
            $iDay      = DllStructGetData($datetime, $ST_DAY  )
            $iYear    = DllStructGetData($datetime, $ST_YEAR )
            $iHours  = DllStructGetData($datetime, $ST_HOUR  )
            $iMinutes   = DllStructGetData($datetime, $ST_MINUTE)
            $iSeconds   = DllStructGetData($datetime, $ST_SECOND)
            
            $shout = StringFormat("%4d/%02d/%02d", $iYear , $iMonth, $iDay);, $iHours, $iMinutes, $iSeconds);, $sAMPM)
            if $ShowLocalTime Then
                $dateback =  _DateAdd('h', guictrlread($Input1), $shout)
            Else
                $dateback = $shout
            EndIf
            
            $dateback = StringFormat("%s %02d:%02d:%02",$dateback , $iHours, $iMinutes, $iSeconds);
            $dt = stringsplit($dateback,' ')
            $dd = stringsplit($dt[1],'/')
            $ddflip = $dd[3] & '/' & $dd[2] & '/' & $dd[1]
            
            $ukdatetime= $ddflip & '|' & $dt[2]
            $filename = DllStructGetData($WIN32_FIND_DATA, 9)
            
            
            $ret[0] = $ret[0] & $filename & '|' & $ukdatetime & "#"
            
        EndIf
        If DllStructGetData($WIN32_FIND_DATA, 1) = 16 Then
            
            
            
            DllStructSetData($fd, 1, DLLStructGetData($WIN32_FIND_DATA, 4,1))
            DllStructSetData($fd, 2, DLLStructGetData($WIN32_FIND_DATA, 4,2))
            $datetime = _FileTimeToSystemTime($fd)
            $iMonth  = DllStructGetData($datetime, $ST_MONTH)
            $iDay      = DllStructGetData($datetime, $ST_DAY  )
            $iYear    = DllStructGetData($datetime, $ST_YEAR )
            $iHours  = DllStructGetData($datetime, $ST_HOUR  )
            $iMinutes   = DllStructGetData($datetime, $ST_MINUTE)
            $iSeconds   = DllStructGetData($datetime, $ST_SECOND)
            
            $shout = StringFormat("%4d/%02d/%02d", $iYear , $iMonth, $iDay);,
                        
            if $ShowLocalTime Then
                $dateback =  _DateAdd('h', guictrlread($Input1), $shout)
                if $dateback = 0 then msgbox(0,"error number from _DAteAdd",@error)
            Else
                $dateback = $shout
            EndIf
            $dateback = StringFormat("%s %02d:%02d:%02",$dateback , $iHours, $iMinutes, $iSeconds);
            $dt = stringsplit($dateback,' ')
            $dd = stringsplit($dt[1],'/')
            $ddflip = $dd[3] & '/' & $dd[2] & '/' & $dd[1]
            
            $ukdatetime = $ddflip & '|' & $dt[2]
            $filename = DllStructGetData($WIN32_FIND_DATA, 9)
            
            $ret[1] = $ret[1] & $filename & '|' & $ukdatetime & "#"
            
        EndIf
        
        Local $callFindNext = DllCall('wininet.dll', 'int', 'InternetFindNextFile', 'long', $callFindFirst[0], 'ptr', DllStructGetPtr($WIN32_FIND_DATA))
        If Not $callFindNext[0] Then
            ExitLoop
        EndIf
    WEnd
    
    _FTPFileFindClose($callFindFirst[0], $WIN32_FIND_DATA)
    $WIN32_FIND_DATA = 0;destroy the struct
    $fd = 0;destroy the struct
    Return $ret
EndFunc;==>_FTPListFiles
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...