Redline
AutoIT Гуру
- Сообщения
- 506
- Репутация
- 375
Функция рекурсивно обходит указанную директорию на FTP, на выходе получается массив (описание массива см. в _FTP_FindFileFirst) с полными путями до файлов/папок.
Ключ $iFilesAndFolders указывает что выводить в массив: только файлы/файлы + папки.
Новый вариант с изменением текущей директории сервера
Первоначальный вариант:
Ключ $iFilesAndFolders указывает что выводить в массив: только файлы/файлы + папки.
Новый вариант с изменением текущей директории сервера
Код:
#include <FTPEx.au3>
#include <Array.au3>
$hFtp = _FTP_Open('ftp_session')
$hSession = _FTP_Connect($hFtp, 'ftp-ip', 'usr', 'pswd')
Global $aList[1][6]
$aList[0][0] = 'Filename'
$aList[0][1] = 'Filesize'
$aList[0][2] = 'FileAttr'
$aList[0][3] = 'DateModif'
$aList[0][4] = 'DateCreate'
$aList[0][5] = 'DateAccess'
_FTP_GetList('', $aList, 0)
_FTP_Close($hFtp)
_ArrayDisplay($aList)
Func _FTP_GetList($sPath, ByRef $aList, $iFilesAndFolders = 1)
$sPath = StringRegExpReplace($sPath, '(^(\\|/)+|(^.+))', '\\$3')
_FTP_DirSetCurrent($hSession, $sPath)
$aFind = _FTP_ListToArrayEx($hSession)
If $aFind <> 0 Then
For $i = 1 To $aFind[0][0]
$iCount = UBound($aList)
If BitAND($aFind[$i][2], $FILE_ATTRIBUTE_DIRECTORY) Then
If $iFilesAndFolders = 1 Then
ReDim $aList[UBound($aList) + 1][6]
$aList[$iCount][0] = $sPath & '\' & $aFind[$i][0]
$aList[$iCount][1] = $aFind[$i][1]
$aList[$iCount][2] = $aFind[$i][2]
$aList[$iCount][3] = $aFind[$i][3]
$aList[$iCount][4] = $aFind[$i][4]
$aList[$iCount][5] = $aFind[$i][5]
ConsoleWrite($sPath & '\' & $aFind[$i][0] & @CRLF)
EndIf
_FTP_GetList($sPath & '\' & $aFind[$i][0], $aList, $iFilesAndFolders)
Else
ReDim $aList[UBound($aList) + 1][6]
$aList[$iCount][0] = $sPath & '\' & $aFind[$i][0]
$aList[$iCount][1] = $aFind[$i][1]
$aList[$iCount][2] = $aFind[$i][2]
$aList[$iCount][3] = $aFind[$i][3]
$aList[$iCount][4] = $aFind[$i][4]
$aList[$iCount][5] = $aFind[$i][5]
ConsoleWrite($sPath & '\' & $aFind[$i][0] & @CRLF)
EndIf
Next
EndIf
EndFunc ;==>_FTP_GetList
Первоначальный вариант:
Код:
#include <FTPEx.au3>
#include <Array.au3>
$hFtp = _FTP_Open('session_name')
$hSession = _FTP_Connect($hFtp, 'ftp_name/ftp_ip', 'name', 'passwd')
Global $aList[1][12]
_FTP_GetTree('', $aList, 0)
_FTP_Close($hFtp)
_ArrayDisplay($aList)
Func _FTP_GetTree($sPath, ByRef $aList, $iFilesAndFolders = 1)
Local $aFind, $hFind, $iCounter = 0, $iPos, $iPlace
$aFind = _FTP_FindFileFirst($hSession, $sPath, $hFind)
While Not @error
$iPos = 0
$iPlace = UBound($aList)
If BitAND($aFind[1], $FILE_ATTRIBUTE_DIRECTORY) Then
If $iFilesAndFolders Then
ReDim $aList[UBound($aList) + 1][12]
$aList[0][0] = $iPlace
$aList[$iPlace][0] = $aFind[0]
$aList[$iPlace][1] = $aFind[1]
$aList[$iPlace][2] = $aFind[2]
$aList[$iPlace][3] = $aFind[3]
$aList[$iPlace][4] = $aFind[4]
$aList[$iPlace][5] = $aFind[5]
$aList[$iPlace][6] = $aFind[6]
$aList[$iPlace][7] = $aFind[7]
$aList[$iPlace][8] = $aFind[8]
$aList[$iPlace][9] = $aFind[9]
$aList[$iPlace][10] = $sPath & '\' & $aFind[10]
$aList[$iPlace][11] = $aFind[11]
EndIf
_FTP_FindFileClose($hFind)
_FTP_GetTree($sPath & '\' & $aFind[10], $aList, $iFilesAndFolders)
$aFind = _FTP_FindFileFirst($hSession, $sPath, $hFind)
$iPos = $iCounter
Else
ReDim $aList[UBound($aList) + 1][12]
$aList[0][0] = $iPlace
$aList[$iPlace][0] = $aFind[0]
$aList[$iPlace][1] = $aFind[1]
$aList[$iPlace][2] = $aFind[2]
$aList[$iPlace][3] = $aFind[3]
$aList[$iPlace][4] = $aFind[4]
$aList[$iPlace][5] = $aFind[5]
$aList[$iPlace][6] = $aFind[6]
$aList[$iPlace][7] = $aFind[7]
$aList[$iPlace][8] = $aFind[8]
$aList[$iPlace][9] = $aFind[9]
$aList[$iPlace][10] = $sPath & '\' & $aFind[10]
$aList[$iPlace][11] = $aFind[11]
EndIf
For $i = 0 To $iPos
$aFind = _FTP_FindFileNext($hFind)
Next
$iCounter += 1
WEnd
_FTP_FindFileClose($hFind)
EndFunc ;==>_FTP_GetTree