#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Posts
    7
    Rep Power
    0

    Question FtpLogin problems with ftpLib from VxWorks


    Hi,

    I want to include a ftp client in my VxWorks application. I have found frpLib (http://www.vxdev.com/docs/vx55man/vxworks/ref/ftpLib.html#ftpLs) which should help me with this.
    My test function should just list the files within the home directory so I came up with this code:
    Code:
    int Get_ftp_file(char *pHost, char *pFilename)
    {    
        int fd;
    
        if (fd = ftpHookup(pHost) == ERROR) {
        	printf("ERROR in ftpHookup()\n");
        	return ERROR;
        }
        
        if(ftpLogin( fd, "ge", "***", "**")== ERROR) {
        	printf("ERROR in ftpLogin()\n");
        	return ERROR;
        }
        if(ftpLs(".")==ERROR) {
        	printf("ERROR in ftpLs()\n");
    		return ERROR;
        }
        	
    }
    And I keep getting an Error on ftpLogin().
    Looking with Wireshark to see what's going on, I see that the connection to the server gets established, I see the response from "vsFTP 3.0.2" but then, I do not see my VxWorks client sending the username at all, I would expect to see something like Request: USER ** and then a reponse that asks for the password Response: 331 Please specify the password followed by a message like Request: PASS ** but I don't see any of that. What am I missing or doing wrong here?

    Thank you for any assistance - oh and HAPPY FRIDAY! :)
    Last edited by reggler; December 6th, 2013 at 01:06 PM. Reason: clarifying the expected messages server- client
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,407
    Rep Power
    1871
    A couple of thoughts.

    1. Enable diagnostics in the package.
    http://www.vxdev.com/docs/vx55man/vx...DebugOptionSet

    2. Login to the ftp server using a regular FTP client, and observe the differences using wireshark. The difference in the trace between regular FTP client and your code is where you should look for differences.

    3. Enable warnings in your compiler.
    > if (fd = ftpHookup(pHost) == ERROR)

    You've written this
    if (fd = (ftpHookup(pHost) == ERROR))

    You probably want this
    if ((fd = ftpHookup(pHost)) == ERROR)

    Comments on this post

    • clifford agrees : Well spotted with the parentheses. ftpHookup() succeeds, but fd will be assigned the boolean false (zero), so ftpLogin() will fail.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,116
    Rep Power
    1803
    Salem's point (3) is almost certainly your problem, and the error is a good example of the folly of your coding style.

    First of all before asking here you might have perhaps checked the value of fd in your debugger.

    Second, you'd have been far less likely to have fallen foul of this issue had you not used the rather dubious practice of assignment within a condition. You seem to have understood the problem but misapplied the solution. It is so easy to get wrong, the best approach is to avoid it altogether and separate the assignment from the conditional test.

    Another practice that is dubious is calling a function withing a conditional. Explicitly assigning the return to a variable allows you to observe the variable in your debugger.

    Yet another problem with your function code is that if it is successful, there is no explicit return statement, - it will return an undefined value which may look like ERROR. Multiple return statements from a function is another dubious practice you should avoid. There may as in this case be paths that do not explicitly return, and having a single return, immediately before the closing brace of the function provides a single point at which to place a break point while debugging and testing your code.

    C Code:
    STATUS Get_ftp_file(char *pHost, char *pFilename)
    {    
        STATUS status = OK ;
        int fd = status = ftpHookup(pHost) ;
     
        if( status  == ERROR) 
        {
        	printf("ERROR in ftpHookup()\n");
        }
        else
        {
            status = ftpLogin( fd, "ge", "***", "**") ;
            if( status == ERROR) 
            {
        	    printf( "ERROR in ftpLogin()\n" ) ;
            }
            else
            {
                status = ftpLs( "." ) ;
                if( status == ERROR )
                {
                    printf( "ERROR in ftpLs()\n" ) ;
                }
            }
        }
     
        return status ;    	
    }


    If you do not really need to report the specific function that fails, you can flatten this somewhat:

    C Code:
    STATUS Get_ftp_file( char *pHost, char *pFilename )
    {    
        STATUS status = OK ;
        int fd = status = ftpHookup(pHost) ;
     
        if( status == OK) 
        {
            status = ftpLogin( fd, "ge", "***", "**") ;
        }
     
        if( status == OK) 
        {
            status = ftpLs(".") ;
        }
     
        if( status  == ERROR) 
        {
        	printf( "ERROR in %s()\n", __FUNCTION__ ) ;
        }
     
        return status ;    	
    }
    Last edited by clifford; December 7th, 2013 at 02:50 PM.

IMN logo majestic logo threadwatch logo seochat tools logo