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?
extern "C"
int cli_ftpgetimage(int fd, int n, char *args[])
{
if( n < 3 || n > 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->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 <= 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 > 0 && 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 < BUFFER_SIZE)
{
naCliPrintf(fd, "%9ld\r", s_dwFileSize);
result = FCGetData(hFC, &pBuffer[s_dwFileSize], 16*1024);
if( result == NAFTPC_EOF ) break;
if( result < 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;
}