Announcement

Collapse
No announcement yet.

FTP recursive download

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • FTP recursive download

    Hi, I have gone through all of IndigoRose website looking for a way for downloading recursively using ftp and cannot find anything. I was able to get ftp to download the folders and the files in the root directory, but nothing else.

    Does anyone have some ideas or code to ftp recursively download?
    Or is the ftp dll unable to do recursion?

    thanks .G

  • #2
    There is no built-in function to download a folder and sub folders via FTP, you need to implement this in script.

    Create a function, which takes a folder path as the argument. In the function, list the contents of that folder passed as the argument. Iterate over all results found in the folder. If the item is a file, download it, if it is a (sub) folder, call the function recursively and create the local folder name as required. It is not complicated.

    You can find a sample which works in a similar way, but uploading a local folder and all of its subfolders, here. If you understood the concept, you won't have any issues creating a script which would download a folder recursively.

    Ulrich

    Comment


    • #3
      I have tried this with no success

      this is a hack of what I have already tried, one of many many different modifications to it, and nothing seems to work, it hangs, so its really hard to work out where or why
      because you cant break in code either.
      then to go up a folder once it has found all the files
      but going deeper into more folders, how? who knows how many files and folders ...
      i have looked on the internet for example iterations and nothing can be found
      just an example would be helpful

      function UpdateList()
      FTP.ClearLog();
      -- get the folders and files separately so we can display
      -- the folders first (at the top of the list box)
      targetFolder = "E:\\atest"

      local tbFolders = FTP.ListFolders();
      --local tbFiles = FTP.ListFiles();

      -- empty the listbox
      ListBox.DeleteItem("DirList_listbox",LB_ALLITEMS);

      -- are we below the root dir?
      if Input.GetText("Path_input") ~= "/" then
      -- we're at least one level "down"
      -- so add a special "up" folder at the top of the list box
      ListBox.AddItem("DirList_listbox","[ ] ..","..");
      end

      -- add the folders to the list box ,.....sowe can see whats happening.
      -- note that we store the undecorated folder name in the item data so we can
      -- get the folder name from the list box without any parsing
      for i = 1,tbFolders.Count do
      ListBox.AddItem("DirList_listbox","[ ] "..tbFolders[i].Name,tbFolders[i].Name);
      --result = Dialog.Message("Notice", "fold "..tbFolders[i].Name, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
      -- check for zero or null
      varstr = tbFolders[i].Name
      --if varstr == "." or varstr == ".." then
      --else
      --strDir = FTP.GetCurrentDir();
      --result = Dialog.Message("Notice", varstr, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
      -- newfolder = targetFolder.."\\"..tbFolders[i].Name

      newfolder = targetFolder.."\\"..varstr
      folderexists = Folder.DoesExist(newfolder);
      if folderexists then
      else
      Folder.Create(newfolder); --Creates folder on the HDD corresponding to the FTP folder
      --error = Application.GetLastError();
      end

      --result = Dialog.Message("Notice", tbFolders[i].Name, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

      --FTP.ChangeDir(varstr) --Changes to this folder

      tbFiles = FTP.ListFiles(); --Gets list of files

      if tbFiles.Count == 0 then
      FTP.CdUp();
      else
      for i = 1,tbFiles.Count do
      --result = Dialog.Message("Notice",varstr.."<fldr>".. newfolder.."\\"..tbFiles[i].Name, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

      FTP.Download(varstr, newfolder.."\\"..tbFiles[i].Name, nil); --Downloads the files to the corresponding folder on HDD
      --err = Application.GetLastError(); --Check if there was errors
      --ListBox.AddItem("DirList_listbox",tbFiles[i].Name,"FILE");
      end

      end
      --result = Dialog.Message("Notice", error, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
      --end
      --Folder.Create("e:\\atest\\test");
      end

      -- add the files to the list box
      -- note that we store the word "FILE" in the item data so we can identify
      -- which items are files and which are folders
      --for i = 1,tbFiles.Count do
      --ListBox.AddItem("DirList_listbox",tbFiles[i].Name,"FILE");
      --end
      end

      Comment


      • #4
        I don't see in your code the concept I described in my reply. There is no recursion, so it can't work. If you checked the example I pointed you to, you already have an example with a recursive function in hands. If you aren't familiar with this programming concept, a recursive function is one that calls itself. Because of this, it will work with any level of subfolders. Trying to hack your way around this may work with one folder structure, but it will fail if there are more or less nested folders...

        Ulrich

        Comment


        • #5
          thanks, but I am no more wiser. The recursion I understand what it means, making it happen is a totally different thing. And with AMS as when the code runs theres no way to know whats happening especially when it crashes during an ftp. Yes I did look through the example code which is for uploading and it doesnt help as its for local files. I looked through every single forum thread that mentions Ftp. Hence thats why I am here many hours later hoping someone can just give me the simplest bit of code for downloading using FTP directories and sub directories and their files, and I will be on my way.

          Comment


          • #6
            The code he posted can be changed to local files also I have been reading them posts and I can see 100% it could be done what your asking, read read read is the point here then learn learn learn, the read some more then try if you want to copy a folder from a FTP folder you going to have to get your get folder option check if that folder has more folders and keep on going until there is a no, you will have to scan each section, AMS really is not the tool for this job but it can be done and has been done, I have seeen a good few FTP examples.
            Plugins or Sources MokoX
            BunnyHop 2021 Here

            Comment


            • #7
              I came here to get help. Instead I got told to do it myself by looking at examples that are not what i need and work it out for yourself. I understand the meaning of recursion and the basics. How do you recursively tell AMS to get ftp Subdirectories and iterate thru them? Simple question. Someone must have done it before. If you want to tell me to do it myself, read alot, learn alot, instead of coming to this forum, then whats the point of the forum, to tease? You either know how and can provide an example or not. Clearly you dont know.

              Comment


              • #8
                Show some respect, don't expect everything on a silver platter. You actually have to do something yourself as a programmer and use the pointers / direction people give you to come to a solution yourself.

                You say you understand recursion, but I don't think you fully grasp the concept. In your case, you would make a function that gets a list of all the files and directories in the current directory (which you set before you call the function). You then apply your download logic on all those files within that function (download them and create directories). For each directory in the list, you CHDIR to that dir, call the function itself again and after that call, you CHDIR back to the current directory.

                The base condition is that when there are no directories any more, the function just returns, breaking the recursion.
                Bas Groothedde
                Imagine Programming :: Blog

                AMS8 Plugins
                IMXLH Compiler

                Comment


                • #9
                  Show some respect, for what? I am just asking for help! not a lecture. I understand recursion, I dont want to reinvent the wheel and spend many many hours doing it if it has been done before, thats the point of having forums. Anyhow I have gone somewhere else, disappointed with the responses, with zero examples of someone having done it before.

                  Comment


                  • #10
                    Originally posted by Savont View Post
                    Show some respect, for what? I am just asking for help! not a lecture. I understand recursion, I dont want to reinvent the wheel and spend many many hours doing it if it has been done before, thats the point of having forums. Anyhow I have gone somewhere else, disappointed with the responses, with zero examples of someone having done it before.
                    Show respect for people trying to point you in the right direction. If you really understand recursion, you would have written that small function yourself based on the pointers people here have given you. If you come here to have other people do your work, you probably shouldn't be here indeed. You should understand your code, instead of just copying it from someone else.
                    Bas Groothedde
                    Imagine Programming :: Blog

                    AMS8 Plugins
                    IMXLH Compiler

                    Comment


                    • #11
                      Originally posted by Savont View Post
                      Show some respect, for what? I am just asking for help! not a lecture. I understand recursion, I dont want to reinvent the wheel and spend many many hours doing it if it has been done before, thats the point of having forums. Anyhow I have gone somewhere else, disappointed with the responses, with zero examples of someone having done it before.
                      There is no other site like IR for the examples and the few users that are about that do help, sadly IR is no longer active and the people that are active will point you HOW to do it not do it for you, I agree with IP here respect is needed, I hope you find what you need and I hope you do it yourself, good look with your project.
                      Plugins or Sources MokoX
                      BunnyHop 2021 Here

                      Comment

                      Working...
                      X