FTP recursive file list
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 121
- Joined: Thu Mar 27, 2008 10:19 am
FTP recursive file list
I'm trying to create a script (using also a routine from "ftp commander" stack) to get a complete list of files (path included) in a FTP site, including all files in subdirectories. The script works partially, but returns only 171 files of 460, and, after many tests, I cannot understand why. Any help?
on listDir myDir
set cursor to watch
put urlEncode(fld "USER") into tUs
put urlEncode(fld "PASS") into tPa
put "ftp://"&tUs&":"&tPa&"@"&myDir into ftpFolder
getFTPlist ftpFolder
put fld "ftp file list" into temp
repeat for each line x in temp
put myDir & "/" & x & return after fld "List"
end repeat
put fld "ftp folder list" into tDirList
repeat with x = 2 to the number of lines of tDirList
listDir (myDir & "/" & (line x of tDirList))
end repeat
end listDir
on getFTPlist ftpfolder
libURLSetFTPListCommand "NLST"
if char -1 of ftpfolder is not "/" then
put "/" after ftpfolder
end if
put URL ftpfolder into tData
if the result contains "error" then
answer the result
exit to top
end if
replace crlf with cr in tData
replace lf with cr in tData
libURLSetFTPListCommand "LIST"
put URL ftpfolder into tLongData
put empty into fld "ftp folder list"
put empty into fld "ftp file list"
repeat with x = 1 to the number of lines of tData
get line x of tData
get lineoffset(it, tLongData)
if char 1 of line it of tLongData is "d" or char 1 of line x of tLongData is "l" then
put line x of tData & cr after fld "ftp folder list"
else
put line x of tData & cr after fld "ftp file list"
end if
end repeat
end getFTPlist
on listDir myDir
set cursor to watch
put urlEncode(fld "USER") into tUs
put urlEncode(fld "PASS") into tPa
put "ftp://"&tUs&":"&tPa&"@"&myDir into ftpFolder
getFTPlist ftpFolder
put fld "ftp file list" into temp
repeat for each line x in temp
put myDir & "/" & x & return after fld "List"
end repeat
put fld "ftp folder list" into tDirList
repeat with x = 2 to the number of lines of tDirList
listDir (myDir & "/" & (line x of tDirList))
end repeat
end listDir
on getFTPlist ftpfolder
libURLSetFTPListCommand "NLST"
if char -1 of ftpfolder is not "/" then
put "/" after ftpfolder
end if
put URL ftpfolder into tData
if the result contains "error" then
answer the result
exit to top
end if
replace crlf with cr in tData
replace lf with cr in tData
libURLSetFTPListCommand "LIST"
put URL ftpfolder into tLongData
put empty into fld "ftp folder list"
put empty into fld "ftp file list"
repeat with x = 1 to the number of lines of tData
get line x of tData
get lineoffset(it, tLongData)
if char 1 of line it of tLongData is "d" or char 1 of line x of tLongData is "l" then
put line x of tData & cr after fld "ftp folder list"
else
put line x of tData & cr after fld "ftp file list"
end if
end repeat
end getFTPlist
i didn't look too closely at your code, but when making a directory walker, there's two errors i often make:
first I often forget to track back, so for example if I have directories like this:
When I don't track back, and start anew with 2, I'll just get dirs 1, 1.1. the directories 1.2 and 2.1 on the other hand are not included, because the code is satisfied with getting all "top level" directories, and the first subdirectory tree it finds.
Another similar problem could happen when I try to include all subdirectories, but forget all the other "top level" ones, including only 1, 1.1, 1.2 and 2.1.
first I often forget to track back, so for example if I have directories like this:
Code: Select all
dir 1
- dir 1.1
- dir 1.2
dir 2
- dir 2.1
Another similar problem could happen when I try to include all subdirectories, but forget all the other "top level" ones, including only 1, 1.1, 1.2 and 2.1.
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
-
- Posts: 121
- Joined: Thu Mar 27, 2008 10:19 am
-
- Posts: 121
- Joined: Thu Mar 27, 2008 10:19 am
There's just way too many things that could go wrong, especially when dealing with a server over the internet. If you can drill the problem down to a single command, or a short, repeatable recipe, then people can offer you alternative, but normally they won't write the whole code for you.
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
-
- Posts: 121
- Joined: Thu Mar 27, 2008 10:19 am
I have never thought to expect that someone wrote the whole code for me; I've wrote a semi-functional code , hoping that someone (with similar interests or needs) could test it on his own site and maybe suggest me some change, for mutual benefit and for the other revolution developers.
If nobody is interested, never mind and thanks however.
If nobody is interested, never mind and thanks however.