Club Builder - Foros de discusión Club Builder
Foro de C++Builder en español
 
 FAQFAQ   BuscarBuscar   MiembrosMiembros   Grupos de UsuariosGrupos de Usuarios   RegistrarseRegistrarse 
 PerfilPerfil   Entra para ver tus mensajes privadosEntra para ver tus mensajes privados   EntrarEntrar 

NMFTP1->Nlist() Duda

 
Publicar nuevo tema   Responder al tema    Foros de discusión -> Consultas
Ver tema anterior :: Ver tema siguiente  
Autor Mensaje
Mensaje    Asunto: NMFTP1->Nlist() Duda Responder citando

A ver...
La duda es la siguiente...
Se supone que con
NMFTP1->Nlist();
creo una lista con los nombres de los archivos que hay en el currentdirectory del nmftp no?
Lo que no se es en el "OnListItem", como hacer para sabes esos nombre y por ejemplo agregarlos a un memo...
Si alguien sabe como se usa eso, por favooooooor que me indique, o me de pistas.
GRACIAS DE ANTEMANO!!
_________________
Saludetes
Volver arriba
Ver perfil de usuario Enviar mensaje privado
Mensaje    Asunto: Responder citando

Pues buscando dentro de la ayuda de Builder, he encontrado lo siguiente
Código:

Example

To recreate this example, you will need to create a new blank C Builder application.

Place 3 TEdits, 9 TButtons, 2 TMemos, a TStatusBar, a TRadioGroup, and a TNMFTP on the form.

Component Descriptions:

Edit1: Host
Edit2: User ID
Edit3: Password
Button1: Connect/Disconnect
Button2: NList
Button3: ChangeDir
Button4: Download
Button5: Upload
Button6: UploadAppend
Button7: UploadUnique
Button8: Upload Restore
Button9: Abort
Memo1: Status Window

Memo2: Directory List display
RadioGroup1: Transfer Mode *
StatusBar1: File Transfer progress

* Change RadioGroup1.Items to MODE_ASCCI, MODE_IMAGE, and MODE_BYTE, in that order.


Insert the following code into Button1's OnClick event:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  if (NMFTP1->Connected)
    NMFTP1->Disconnect();
  else
    {
      NMFTP1->Host = Edit1->Text;
      NMFTP1->UserID = Edit2->Text;

      NMFTP1->Password = Edit3->Text;
      NMFTP1->Connect();
    }
}

When Button1 is clicked, if the Connected property is TRUE, a connection is present, and the Disconnect method is called to disconnect from the remote FTP host. If Connected is FALSE, there is no connection present, so the Host property is set to the value in Edit1 to specify the remote host to connect to. The UserID property is set to the value in Edit2, and the Password property is set to the value in Edit3. The UserID and Password are used to log in to the remote host when connected.

Insert the following code into Button2's OnClick event:

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  Memo2->Clear();
  NMFTP1->NList();
}

When Button2 is clicked, any text being displayed in Memo2 is cleared. The NList method is called, retrieving the names of all files and directories in the current working directory. The results of this method call can be seen in the OnListItem event.


Insert the following code into Button3's OnClick event:

void __fastcall TForm1::Button3Click(TObject *Sender)
{
  AnsiString TheDir;
  if (InputQuery("Change directory", "Directory name?", TheDir))
    NMFTP1->ChangeDir(TheDir);
}

When Button3 is clicked, the InputQuery function is used to obtain the name of the directory desired. If the Ok button is clicked, the ChangeDir method is used to change the current working directory to the directory specified.


Insert the following code into Button4's OnClick event:

void __fastcall TForm1::Button4Click(TObject *Sender)
{
  AnsiString RemoteFile, LocalFile;
  TOpenDialog *O = new TOpenDialog(this);
  if (InputQuery("Download a file", "File to download: ", RemoteFile))
    {
        O->Title = "Save file as";
        if (O->Execute())
          {
            LocalFile = O->FileName;
            switch(RadioGroup1->ItemIndex)
              {
                 case 0: NMFTP1->Mode(MODE_ASCII);

                 case 1: NMFTP1->Mode(MODE_IMAGE);
                 case 2: NMFTP1->Mode(MODE_BYTE);
              }
            NMFTP1->Download(RemoteFile, LocalFile);
          }
    }
}

When Button4 is clicked, the InputQuery function is used to retrieve the name of a remote file to download to the local computer. if the Ok button is clicked, an OpenDialog is used to retrieve the name to store the file as on the local computer. If the Open button is clicked, the Mode method is called, changing the transfer mode depending on the selected item in RadioGroup1. Then the Download method is used to download the remote file to the local disk.

Insert the following code into NMFTP1's OnDisconnect event:

void __fastcall TForm1::NMFTP1Disconnect(TObject *Sender)
{
  Memo1->Lines->Add("Disconnected");
  Button1->Caption = "Connect";
}

When the local computer disconnects from the remote host, the OnDisconnect event is called. In this instance, the status display (Memo1) is updated to display the disconnect status, and the caption of Button1 is changed to Connect (Since Button1 is used for connecting and disconnecting).

Insert the following code into NMFTP1's OnPacketRecvd event:

void __fastcall TForm1::NMFTP1PacketRecvd(TObject *Sender)
{
  StatusBar1->SimpleText = IntToStr(NMFTP1->BytesRecvd)+" bytes received out of "+IntToStr(NMFTP1->BytesTotal);
}

When data is received from the remote host during a file transfer, the OnPacketRecvd event is called. In this instance, StatusBar1 displays the progress of the transfer by displaying the BytesRecvd property, which contains the number of bytes received, and the BytesTotal property, which contains the total number of bytes to transfer.

Insert the following code into NMFTP1's OnPacketSent event:

void __fastcall TForm1::NMFTP1PacketRecvd(TObject *Sender)
{
  StatusBar1->SimpleText = IntToStr(NMFTP1->BytesRecvd)+" bytes received out of "+IntToStr(NMFTP1->BytesTotal);
}

When data is sent to the remote host during a file transfer, the OnPacketSent event is called. In this instance, StatusBar1 displays the progress of the transfer by displaying the BytesSent property, which contains the number of bytes sent, and the BytesTotal property, which contains the total number of bytes to transfer.

Insert the following code into NMFTP1's OnTransactionStart event:

void __fastcall TForm1::NMFTP1TransactionStart(TObject *Sender)
{
  Memo1->Lines->Add("Transaction Start");
}

When a data transfer begins, the OnTransactionStart event is called. In this instance, the Status Memo, Memo1, displays that the transaction started.


Insert the following code into NMFTP1's OnTransactionStop event:

void __fastcall TForm1::NMFTP1TransactionStop(TObject *Sender)

{
  Memo1->Lines->Add("Transaction Stop");
}

When a data transfer completes, the OnTransactionStop event is called. In this instance, the Status Memo, Memo1, displays that the transaction has finished.


Insert the following code into Button5's OnClick event:

void __fastcall TForm1::Button5Click(TObject *Sender)
{
  AnsiString LocalFile, RemoteFile;
  int FileHandle, FSize;
  TOpenDialog *O = new TOpenDialog(this);
  O->Title = "Select file to upload";

  if (O->Execute())
    if (InputQuery("Choose Remote File Name", "Filename?", RemoteFile))
      {
         LocalFile = O->FileName;
         switch(RadioGroup1->ItemIndex)
           {
              case 0: NMFTP1->Mode(MODE_ASCII);
              case 1: NMFTP1->Mode(MODE_IMAGE);
              case 2: NMFTP1->Mode(MODE_BYTE);
           }
         FileHandle = FileOpen(LocalFile, fmOpenRead);
         FSize = FileSeek(FileHandle, 0, 2);

         FileClose(FileHandle);
         NMFTP1->Allocate(FSize);
         NMFTP1->Upload(LocalFile, RemoteFile);
      }
}

When Button5 is clicked, an Open Dialog is displayed to select a file on the local computer to upload to the remote host. If the Open button is clicked, the InputQuery function is used to retrieve the name the file will be stored as on the remote host. If the Ok button is clicked, the file is opened so it's size can be determined. The Allocate method is called to reserve space on the remote host for the file. This is not normally necessary, but is done here to illustrate the use of the method. The Upload method is used to send the file to the remote host.

Insert the following code into Button6's OnClick event:

void __fastcall TForm1::Button6Click(TObject *Sender)
{
  AnsiString LocalFile, RemoteFile;
  TOpenDialog *O = new TOpenDialog(this);
  O->Title = "Select file to upload";
  if (O->Execute())
    if (InputQuery("Choose Remote File Name", "Filename?", RemoteFile))
      {
         LocalFile = O->FileName;
         switch(RadioGroup1->ItemIndex)
           {
             case 0: NMFTP1->Mode(MODE_ASCII);

             case 1: NMFTP1->Mode(MODE_IMAGE);
             case 2: NMFTP1->Mode(MODE_BYTE);
           }
         NMFTP1->UploadAppend(LocalFile, RemoteFile);
      }
}

When Button6 is clicked, an Open Dialog is displayed to select a file on the local computer to upload to the remote host. If the Open button is clicked, the InputQuery function is used to retrieve the name the file will be stored as on the remote host. If the Ok button is clicked, the UploadAppend method is used to send the file to the remote host. If a file with the same name already exists on the remote host, the file being sent is appended to the end of the existing file.

Insert the following code into Button7's OnClick event:

void __fastcall TForm1::Button7Click(TObject *Sender)
{
  AnsiString LocalFile;
  TOpenDialog *O = new TOpenDialog(this);
  O->Title = "Upload file";
  if (O->Execute())
    {
       LocalFile = O->FileName;
       NMFTP1->UploadUnique(LocalFile);
    }
}

When Button7 is clicked, an Open Dialog is displayed to select the file on the local computer to upload to the remote host. If the Open button is clicked, the UploadUnique
 method is used to store the file on the remote FTP host with a unique filename given by the FTP host.

Insert the following code into NMFTP1's OnFailure event:

void __fastcall TForm1::NMFTP1Failure(bool &Handled, TCmdType Trans_Type)
{
  switch(Trans_Type)
    {
       case cmdChangeDir: Memo1->Lines->Add("ChangeDir failure");
       case cmdMakeDir: Memo1->Lines->Add("MakeDir failure");
       case cmdDelete: Memo1->Lines->Add("Delete failure");
       case cmdRemoveDir: Memo1->Lines->Add("RemoveDir failure");

       case cmdList: Memo1->Lines->Add("List failure");
       case cmdRename: Memo1->Lines->Add("Rename failure");
       case cmdUpRestore: Memo1->Lines->Add("UploadRestore failure");
       case cmdDownRestore: Memo1->Lines->Add("DownloadRestore failure");
       case cmdDownload: Memo1->Lines->Add("Download failure");
       case cmdUpload: Memo1->Lines->Add("Upload failure");
       case cmdAppend: Memo1->Lines->Add("UploadAppend failure");

       case cmdReInit: Memo1->Lines->Add("Reinitialize failure");
       case cmdAllocate: Memo1->Lines->Add("Allocate failure");
       case cmdNList: Memo1->Lines->Add("NList failure");
       case cmdDoCommand: Memo1->Lines->Add("DoCommand failure");
       case cmdCurrentDir: Memo1->Lines->Add("CurrentDir failure");
    }
}

When an FTP command fails, the OnFailure event is called. In this case, the Handled parameter is left the default (FALSE), so an exception will be raised, in addition to a failure notification being added to the status display (Memo1) noting the command that failed.

Insert the following code into NMFTP1's OnSuccess event:

void __fastcall TForm1::NMFTP1Success(TCmdType Trans_Type)
{
  switch(Trans_Type)
    {
      case cmdChangeDir: Memo1->Lines->Add("ChangeDir success");
      case cmdMakeDir: Memo1->Lines->Add("MakeDir success");
      case cmdDelete: Memo1->Lines->Add("Delete success");
      case cmdRemoveDir: Memo1->Lines->Add("RemoveDir success");
      case cmdList: Memo1->Lines->Add("List success");

      case cmdRename: Memo1->Lines->Add("Rename success");
      case cmdUpRestore: Memo1->Lines->Add("UploadRestore success");
      case cmdDownRestore: Memo1->Lines->Add("DownloadRestore success");
      case cmdDownload: Memo1->Lines->Add("Download success");
      case cmdUpload: Memo1->Lines->Add("Upload success");
      case cmdAppend: Memo1->Lines->Add("UploadAppend success");
      case cmdReInit: Memo1->Lines->Add("Reinitialize success");

      case cmdAllocate: Memo1->Lines->Add("Allocate success");
      case cmdNList: Memo1->Lines->Add("NList success");
      case cmdDoCommand: Memo1->Lines->Add("DoCommand success");
      case cmdCurrentDir: Memo1->Lines->Add("CurrentDir success");
    }
}

When an FTP command succeeds, the OnSuccess event is called. In this instance, the command that succeeded is displayed in the status display (Memo1).


Insert the following code into Button8's OnClick event:

void __fastcall TForm1::Button8Click(TObject *Sender)
{
  AnsiString LocalFile, RemoteFile, FPos;
  int FPosition;
  TOpenDialog *O = new TOpenDialog(this);
  O->Title = "Select file to upload";
  if (O->Execute())
    if (InputQuery("Choose Remote File Name", "Filename?", RemoteFile))
      if (InputQuery("Choose restoration point", "Byte Count: ", FPos))
        {
          FPosition = StrToInt(FPos);
          LocalFile = O->FileName;

          switch(RadioGroup1->ItemIndex)
            {
              case 0: NMFTP1->Mode(MODE_ASCII);
              case 1: NMFTP1->Mode(MODE_IMAGE);
              case 2: NMFTP1->Mode(MODE_BYTE);
            }
          NMFTP1->UploadRestore(LocalFile, RemoteFile, FPosition);
        }
}

When Button8 is clicked, an OpenDialog is displayed to select a file on the local computer to upload to the remote host. If the Open button is clicked, the InputQuery function is used to retrieve the name the file will use on the remote host. The InputQuery function is called once more to obtain the position to restore the upload from. If the Ok button is clicked, the Mode method is used to set the mode as determined by RadioGroup1. The UploadRestore method continues a previously interrupted upload at the position specified.

Insert the following code into Button9's OnClick event:

void __fastcall TForm1::Button9Click(TObject *Sender)
{
  NMFTP1->Abort();
}

When  Button9 is clicked, the Abort method is called, aborting the current operation.

Espero te sirva de algo...
_________________
Cool
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email MSN Messenger
Mostrar mensajes de anteriores:   
Cambiar a:  
No puedes publicar temas nuevos en este foro
No puedes responder a temas en este foro
No puedes editar tus mensajes en este foro
No puedes borrar tus mensajes en este foro
No puedes votar en las encuestas de este foro


Hosting WordPress Indedmedia desde 3,99 €
© 2002–2026 Club Builder · Funciona con phpBB.