darkjohn20 1 Posted May 13, 2010 Share Posted May 13, 2010 I searched the forums a little, but I couldn't find any recursive FTP file/folder searches. I was wondering if anybody has one? Perhaps I just couldn't find it? I'm bad with recursion so maybe somebody else could write one faster than I could, but if not I can try my best. I'm not sure what a quick or efficient way to do this would be, so any help is appreciated. Link to post Share on other sites
grasshopper3 1 Posted May 13, 2010 Share Posted May 13, 2010 are u looking for one that looks for a certain file or file type or one that list all the files that are in the FTP dir? Link to post Share on other sites
darkjohn20 1 Posted May 13, 2010 Author Share Posted May 13, 2010 (edited) I was looking for one that would list all files, in other words no "include list". I plan to modify it so that a function is called as soon as a file/folder is found, rather than doing it after the function returned. Meaning: If a file is found: Call _FTP_Download(), but if a folder is found: CreateDir(), or something similar. That's my goal. Download everything under a certain path to the desktop, maintaining all file structures. And really, I'm looking at less than 100 folders, most likely less than 100 files. Speed isn't a large issue, but the faster the better. I also don't need a full-out UDF. As long as it works, I don't need much error checking or documentation. A few comments would be nice, but that's it. Edited May 13, 2010 by darkjohn20 Link to post Share on other sites
Yashied 256 Posted May 13, 2010 Share Posted May 13, 2010 expandcollapse popup#Include <FTPEx.au3> _FTP_Download('', @ScriptDir & '\Uploaded', 'ftp.mozilla.org') Func _FTP_Download($sRemotePath, $sLocalPath, $sHost, $sLogin = '', $sPassword = '', $iPassive = 1, $iPort = 0) Local $hFtp, $hSession, $aFind, $hFind, $Path, $Result = 1 DirCreate($sLocalPath) If (Not FileExists($sLocalPath)) Or (Not StringInStr(FileGetAttrib($sLocalPath), 'D')) Then Return 0 EndIf $hFtp = _FTP_Open('MyFtp') $hSession = _FTP_Connect($hFtp, $sHost, $sLogin, $sPassword, $iPassive, $iPort) $aFind = _FTP_FindFileFirst($hSession, $sRemotePath, $hFind) While Not @error $Path = $sLocalPath & '\' & $aFind[10] If BitAND($aFind[1], $FILE_ATTRIBUTE_DIRECTORY) Then DirCreate($Path) If (Not FileExists($Path)) Or (Not StringInStr(FileGetAttrib($Path), 'D')) Then Return 0 EndIf If Not _FTP_Download($sRemotePath & '/' & $aFind[10], $Path, $sHost, $sLogin, $sPassword, $iPassive, $iPort) Then Return 0 EndIf Else ConsoleWrite($sLocalPath & '\' & $aFind[10] & @CR) ; If Not _FTP_FileGet($hSession, $sRemotePath & '/' & $aFind[10], $Path) Then ; $Result = 0 ; EndIf EndIf $aFind = _FTP_FindFileNext($hFind) WEnd _FTP_FindFileClose($hFind) _FTP_Close($hFtp) Return $Result EndFunc ;==>_FTP_Download My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to post Share on other sites
Yashied 256 Posted May 13, 2010 Share Posted May 13, 2010 (edited) This doesn't recurse, it just searches the immediate path. How can I make it recurse into sub-directories?You sure? Edited May 13, 2010 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to post Share on other sites
darkjohn20 1 Posted May 13, 2010 Author Share Posted May 13, 2010 (edited) You sure? Oops, I removed the line to recurse. I tried this and it still didn't work... #include-once #include <FTPEx.au3> Func _FTP_Recurse($hSession, $sRemotePath, $sLocalPath = @DesktopDir) Local $aFind, $hFind, $sPath, $iResult = 1 If StringRight($sLocalPath, 1) <> "\" Then $sLocalPath &= "\" If StringRight($sRemotePath, 1) <> "/" Then $sRemotePath &= "/" DirCreate($sLocalPath) _Splash_Add("Downloading...") $aFind = _FTP_FindFileFirst($hSession, $sRemotePath, $hFind) While Not @error $sPath = $sLocalPath & $aFind[10] If BitAND($aFind[1], $FILE_ATTRIBUTE_DIRECTORY) Then DirCreate($sPath) _Splash_Add("Dir: " & $sPath) _FTP_Recurse($hSession, $sRemotePath & $aFind[10], $sPath) Else _Splash_Add("File: " & $sPath) _FTP_FileGet($hSession, $sRemotePath & $aFind[10], $sPath) EndIf $aFind = _FTP_FindFileNext($hFind) WEnd _FTP_FindFileClose($hFind) Return $iResult EndFunc Edited May 14, 2010 by darkjohn20 Link to post Share on other sites
Yashied 256 Posted May 14, 2010 Share Posted May 14, 2010 I tried this and it still didn't work...You can not open more than one search per session. For each search, you should create a new connection. I gave you a working example... My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to post Share on other sites
darkjohn20 1 Posted May 14, 2010 Author Share Posted May 14, 2010 (edited) You can not open more than one search per session. For each search, you should create a new connection. I gave you a working example...Ahh, my bad. I see what's wrong. Thanks. The only reason I removed that from mine was because I had more FTP actions in my main script. Edited May 14, 2010 by darkjohn20 Link to post Share on other sites
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now