user3714517
user3714517

Reputation: 13

IdFTP, upload directory and subdirectories

I need upload directory and subdirectories on server. I think i need to call method IdFTP->Put(...); But I dont know how to do it. Help me, please!

Upvotes: 0

Views: 1304

Answers (2)

Pavel Rabinovych
Pavel Rabinovych

Reputation: 86

void PutDir(TIdFTP* AIdFTP, const String& AFrom)
{
    TSearchRec SR;
    if (FindFirst(AFrom+"\\*.*", faAnyFile, SR)== 0)
    {
        do
        {
            if(SR.Name!= "." && SR.Name!= "..")
            {
                if (SR.Attr & faDirectory)
                {
                    AIdFTP->MakeDir(SR.Name);
                    AIdFTP->ChangeDir(SR.Name);
                    PutDir(AIdFTP,AFrom+"\\"+SR.Name);
                    AIdFTP->ChangeDirUp();
                }
                else
                {
                    AIdFTP->Put(AFrom+"\\"+SR.Name,SR.Name);
                }
            }
        }
        while (FindNext(SR)== 0);

        FindClose(SR);
    }
}

Upvotes: 2

Remy Lebeau
Remy Lebeau

Reputation: 597051

TIdFTP::Put() uploads a single file. TIdFTP does not natively support uploading folders, so you will have to implement it manually:

  1. use TIdFTP::ChangeDir() to go to the starting parent folder.

  2. use TIdFTP::Put() to upload each file into that folder.

  3. use TIdFTP.MakeDir() to create each subfolder in that folder.

  4. recursively repeat #1 for each subfolder that you created in #3.

Upvotes: 4

Related Questions