Announcement

Collapse
No announcement yet.

FTP Upload of whole Folder including subfolders within

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

  • FTP Upload of whole Folder including subfolders within

    Hi all, I have been trying to get the code to upload(FTP) the complete contents of a Folder but with no success.

    Here is my code:


    function ERRORCHECKING()

    err = Application.GetLastError();

    if err ~= 0 then
    strErrMsg = _tblErrorMessages[err];
    Dialog.Message("Error: ", strErrMsg);
    end
    end

    --------------------------------------------------------------------------
    --------------------------------------------------------------------------

    host = "*******" --
    username ="****" --
    password = "*****" --



    Folder = Dialog.FolderBrowse("Please select a folder:", _DesktopFolder);


    Files = File.Find(Folder, "*.jpg", true, true, nil);


    file_count = Table.Count(Files);



    FTP.Connect(host, username, password, "", true);
    ERRORCHECKING();


    FTP.ChangeDir("/public_html/Test");
    ERRORCHECKING();

    FTP.MakeDir(Folder);
    ERRORCHECKING();



    -- For each file in the chosen folder
    -- first update the 'Status Dialog' box
    -- then, upload each file in the chosen
    -- folder
    for n=1,file_count do
    StatusDlg.SetMeterRange(0, file_count);
    StatusDlg.Show(MB_ICONINFORMATION, false);
    StatusDlg.SetMeterPos(n);
    StatusDlg.SetTitle("FTP Upload Status . . .");
    StatusDlg.SetMessage("FTP Upload in progress . . .");
    StatusDlg.SetStatusText("Uploading file"..n.." of a total "..file_count);

    FTP.Upload(Files[n], n..".jpg", nil);
    ERRORCHECKING();
    end

    StatusDlg.Hide();

    FTP.Disconnect();

    Dialog.TimedMessage("FTP Notice!", "Finished uploading!", 2000, MB_ICONINFORMATION);




  • #2
    What are the error messages telling you? What does actually happen, and where does your script stop working as expected?

    I don't think that you can create a folder with a Windows/DOS name like "C:\folder" via FTP, but there might be other errors.

    Ulrich

    Comment


    • #3
      Hi,

      It gives me a dialog message " Unknown error" but does actually copy a single file within the folder that it names as 1.jpeg.
      The folder name that I select when it prompts me is named Photo and in Photo is a single photo file photo.jpg and another folder.

      Strange that it then only copies the one photo file inside and names it something else??

      Comment


      • #4
        The folder name that I select when it prompts me is named Photo and in Photo is a single photo file photo.jpg and another folder.

        Strange that it then only copies the one photo file inside and names it something else??
        If you have a single file in the folder, and this file is uploaded, then there is no error. You are telling to upload it as n..".jpg", so clearly you aren't keeping the original name.

        FTP does not automatically create sub folders. If you need sub folders, you must first create them, and change the active folder on the FTP server before you upload the file. FTP does not upload into a sub folder directly, and the only folder change operation you have is hardcoded - FTP.ChangeDir("/public_html/Test").

        Ulrich

        Comment


        • #5
          Thanks Ulrich

          Is there anybody out there willing to point in in the right right direction towards the coded needed to do this?
          Regards

          Comment


          • #6
            Would there be a way to maybe transfer a zip file and then have some code to unzip it on the server?

            Comment


            • #7
              Building a sample will take some time. I have started, but there is still code to be written.

              There is no command in the FTP protocol that would decompress a zip file after transfer. Of course, you may have a CGI script or a ASP/PHP web page which could process the local file after upload, but nothing that would happen automagically.

              Ulrich

              Comment


              • #8
                Here is a sample project, which will upload a folder to a remote FTP server. All sub folders and files contained in the source folder will be transferred as well.

                There are several things that can be added to enhance this project, like showing progress for each individual file upload, and adding a button to abort the transfer at any moment. Both can be created by implementing the custom callback function, which is a good learning exercise.

                There will be a log file named "ftp-debug.txt" in the _TempFolder, with details about the actions performed during the upload.

                Please note that the program was written in such a manner that the target folder must exist on the FTP server, but any sub folders are created as required. If you don't want this, you can change the code as desired, or you can contact me at my web site.

                Ulrich
                Attached Files

                Comment


                • #9
                  Wow... thanks a mil !!!
                  Very much appreciated!
                  R

                  Comment


                  • #10
                    Ulrich,
                    Can I push my luck a little bit further in asking what code must I add to have it check if the folder on the server already exists incase you don't want to override ?? I have tried adding a few lines, but it wont work!!

                    Cheers mate and thanks for all the help.

                    Comment


                    • #11
                      Hello,
                      Maybe this thread will help you link. The last code has a bug, I fixed it, but as someone stole my laptop I do not have any copy of it.

                      Comment


                      • #12
                        Thanks claus!!

                        Comment

                        Working...
                        X