# FCConnect() failure

**URL:** <https://forums.digi.com/t/fcconnect-failure/5855>\
**Category:** NET+OS\
**Created:** [August 11, 2010, 11:59pm UTC](https://forums.digi.com/t/fcconnect-failure/5855 "2010-08-11T23:59:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![egawtry](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@egawtry](https://forums.digi.com/u/egawtry)\
**Post date:** [August 11, 2010, 11:59pm UTC](https://forums.digi.com/t/fcconnect-failure/5855/1 "2010-08-11T23:59:25Z")

</div>

I added the following CLI call but FCConnect() returns NAFTPC\_CONNECTION\_RESET every time. Anyone with an idea?

Thanks,  
-Erik

P.S. How do I preserve tabs in a [code] insert?

```auto

extern "C" 
int cli_ftpgetimage(int fd, int n, char *args[])
{
        if( n &lt; 3 || n &gt; 4 ) return 1;
        
        char szFilename[256], szPath[256], szIP[32], szLogin[32], szPassword[32];

        strcpy(szFilename, args[0]);
        if( !isdigit(*args[1]) )
        {
                hostent *he = _gethostbyname(args[1]);
                if( !he )
                {
                        naCliPrintf(fd, "ftp: Invalid Hostname
");
                        return 1;
                }
                strcpy(szIP, inet_ntoa(*((in_addr *)he-&gt;h_addr_list[0])));
        }
        else
                strcpy(szIP, args[1]);
                
        strcpy(szLogin, args[2]);
        if( args[3] )
                strcpy(szPassword, args[3]);
        else
                strcpy(szPassword, "");

        s_dwFileSize = 0;
        _fd = fd;

        bHideTrace = true;
        
        {
                char *ptr;
                if( (ptr=strrchr(szFilename, '/')) || (ptr=strrchr(szFilename, '\\')) )
                {
                        *ptr++ = '\0';
                        strcpy(szPath, szFilename);
                        strcpy(szFilename, ptr);
                        while( (ptr=strchr(szPath, '\\')) ) *ptr = '/';
                }
                else
                        strcpy(szPath, "");
        }

        naCliPrintf(fd, "ftp get %s:%s%s
", szIP, szPath, szFilename);

        if( GetDataPointer() == NULL )
        {
                naCliPrintf(fd, "
Error: Cannot allocate download buffer
");
                bHideTrace = false;
                return 1;
        }
        
        NAHANDLE hFC = FCConnect(szIP, szLogin, szPassword);
        
        if( hFC &lt;= 0 )
        {
                naCliPrintf(fd, "Connect: ");
ShowError:
                switch(hFC)
                {
                case NAFTPC_INVALID_SERVER: naCliPrintf(fd, "Invalid server
"); break;  
                 case NAFTPC_INVALID_USER: naCliPrintf(fd, "Invalid user
"); break;
                 case NAFTPC_INVALID_PASS: naCliPrintf(fd, "Invalid password
"); break;
                 case NAFTPC_NO_MEMORY: naCliPrintf(fd, "Malloc failed
"); break;
                 case NAFTPC_CREATE_SEM_FAIL: naCliPrintf(fd, "Create Semaphore failed
"); break;
                 case NAFTPC_SOCKERR: naCliPrintf(fd, "Socket error
"); break; 
                 case NAFTPC_CONNECTION_REFUSED: naCliPrintf(fd, "Specified server address is not waiting for connections
"); break;
                 case NAFTPC_TIMEOUT: naCliPrintf(fd, "Time out before connected to server
"); break;
                 case NAFTPC_INVALID_REPLY: naCliPrintf(fd, "Received invalid reply from server.
"); break;
                 case NAFTPC_LOGON_FAILED: naCliPrintf(fd, "Can't logon, wrong username or password
"); break;
                 case NAFTPC_LOW_NETWORK_HEAP: naCliPrintf(fd, "Network heap is low.
"); break;
                case NAFTPC_INVALID_HANDLER: naCliPrintf(fd, "Invalid FTP session.
"); break;
                 case NAFTPC_HANDLER_NOT_EXIST: naCliPrintf(fd, "Bad FTP session.
"); break;
                case NAFTPC_INVALID_PATHNAME: naCliPrintf(fd, "Invalid path name
"); break;
                 case NAFTPC_INVALID_FILETYPE: naCliPrintf(fd, "Invalid file type
"); break;
                case NAFTPC_EOF: naCliPrintf(fd, "No more data; end-of-file has been reached.
"); break;
                case NAFTPC_INVALID_BUFFER: naCliPrintf(fd, "Null buffer pointer
"); break;
                 case NAFTPC_INVALID_LEN: naCliPrintf(fd, "Invalid buffer length
"); break;
                 case NAFTPC_CONNECTION_RESET: naCliPrintf(fd, "Connection reset by the server.
"); break;
                 default: naCliPrintf(fd, "Unknown Error %d
", hFC); break;
                 }
                bHideTrace = false;
                return 1;
        }

        if( szPath[0] )        
        {
                char szOldPath[256];
                int len;
                
                FCGetCurrentDir(hFC, szOldPath, 256);
                len = (int)strlen(szOldPath);
                if( len &gt; 0 &amp;&amp; szOldPath[len-1] == '/' ) szOldPath[len-1] = '\0';
                if( strcmp(szOldPath, szPath) )
                {
                        FCSetCurrentDir(hFC, (char *)"/");
                        FCSetCurrentDir(hFC, szPath);
                }
        }        
        
        {
                int result = FCRetrieveFile(hFC, szFilename, NAFTPC_TYPE_BIN);
                
                if( result != NAFTPC_NOERROR )
                {
                        naCliPrintf(fd, "GET: ");
                        FCDisconnect(hFC);
                        hFC = (NAHANDLE)result;
                        goto ShowError;
                }
                
                s_dwFileSize = 0;
                char *pBuffer = (char *)GetDataPointer();
                
                while(s_dwFileSize &lt; BUFFER_SIZE)
                {
                        naCliPrintf(fd, "%9ld\r", s_dwFileSize);
                        
                        result = FCGetData(hFC, &amp;pBuffer[s_dwFileSize], 16*1024);
                
                        if( result == NAFTPC_EOF ) break;
                        if( result &lt; 0 )
                        {
                                naCliPrintf(fd, "%9ld
Receive: ", s_dwFileSize);
                                FCDisconnect(hFC);
                                hFC = (NAHANDLE)result;
                                goto ShowError;
                        }
                
                        s_dwFileSize += result;
                }
                naCliPrintf(fd, "%9ld
Download Complete.
", s_dwFileSize);
        }
        
        FCDisconnect(hFC);
        bHideTrace = false;
        return 0;
}

```

---

<div class="post-metadata">

**Author:** ![kjensen8](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@kjensen8](https://forums.digi.com/u/kjensen8)\
**Post date:** [August 12, 2010, 3:50pm UTC](https://forums.digi.com/t/fcconnect-failure/5855/2 "2010-08-12T15:50:35Z")

</div>

Hi Erik!

some basic questions:  
-are you sure the FTP server is responding? can you connect to it manually with some other client?  
-can you connect to it via NETOS with a simple app with the FCConnect() parameters hard coded?

---

<div class="post-metadata">

**Author:** ![egawtry](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@egawtry](https://forums.digi.com/u/egawtry)\
**Post date:** [August 12, 2010, 4:43pm UTC](https://forums.digi.com/t/fcconnect-failure/5855/3 "2010-08-12T16:43:34Z")

</div>

1. I can FTP from the Windows command line without at hitch.
2. I hard coded the entries and I still get the same results.

-Erik

---

<div class="post-metadata">

**Author:** ![egawtry](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@egawtry](https://forums.digi.com/u/egawtry)\
**Post date:** [August 30, 2010, 8:30pm UTC](https://forums.digi.com/t/fcconnect-failure/5855/4 "2010-08-30T20:30:36Z")

</div>

Don’t know why, but I replaced the router/gateway and it worked.
