Logo Search packages:      
Sourcecode: camstream version File versions  Download package

void CFTPClient::Connect ( const QString &  user,
const QString &  pass,
const QString &  server,
int  port = 21 
)

Initiate connection to FTP server.

Parameters:
user The username
pass The password
server The server name
port Port number on the server
This function initiates a connection to the server. This is the only function of CFTPClient that can block, since name resolving is done here, and that is a blocking call.

Definition at line 1020 of file FTPClient.cc.

References CloseAllFD(), SetState(), SetupControl(), stConnected, stFailed, and stNOC.

{
   struct hostent *pServerName;

   if (CtrlFD >= 0) {
     // SendAbort();
     CloseAllFD();
     SetState(stNOC);
   }

   CurrentCommand = cmdLogin;
   InitBuffers();

   /* Step 1: name resolv of server
      Unfortunately, this is a blocking system call. res_mkquery() is not funny.
    */
   pServerName = gethostbyname((const char *)server);
   if (pServerName == NULL) {
     SetState(stFailed, 810);
     return;
#if 0     
     switch(h_errno) { // This is tweaking the error codes somewhat :)
       case TRY_AGAIN:      return -EAGAIN; break;
       case HOST_NOT_FOUND: SetState(stFailed, 810); break;
       case NO_ADDRESS:     return -EFAULT; break;
       case NO_RECOVERY:    return -EINVAL; break;
       default:             return -EBUSY;  break;
     }
#endif     
   }

   if (pServerName->h_length != sizeof(struct in_addr))
     abort(); // Something fishy is going on!
   ServerAddress.sin_family = AF_INET;
   ServerAddress.sin_port = htons(port);
   memcpy(&ServerAddress.sin_addr, pServerName->h_addr_list[0], pServerName->h_length);
qDebug("Resolved server address: %s (%s)", pServerName->h_name, inet_ntoa(ServerAddress.sin_addr));

   UserName = user;
   Password = pass;
   CurrentCommand = cmdLogin;

   /* Set up our control connection; once this is established, 
      this automatically logs in. 
    */
   if (SetupControl() < 0) {
     SetState(stFailed, 811);
     CurrentCommand = cmdNop;
   }

   SetState(stConnected);
}


Generated by  Doxygen 1.6.0   Back to index