LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

InetFTPGetDirList produces server error

I'm trying to write a function that checks for the existance of a file on an ftp server. Using GetDirList seemed to be a good choice. I have no troubles logging onto the ftp server and doing a dir using DOS ftp command, but when I run my code it gives the following error:

NON-FATAL RUN-TIME ERROR: "mainwindow.c", line 462, col 5, thread id 0x0000081C, function id 1: Function InetFTPGetDirList: (return value == -12 [0xfffffff4]). FTP server error

Here is the code, mostly copied directly from the example:

int ftpHandle = 0;
int returnValue = 0;
char **files;
int numFiles = 0, i = 0;

ftpHandle = InetFTPLoginEx("192.168.2.2", username, password, 10000);
InetFTPSetPassiveMode(ftpHandle, 1);
InetFTPChangeDir(ftpHandle, "/");
InetFTPGetDirList(ftpHandle, &files, &numFiles);
if (files != NULL)
{
/* Print the files */
for (i = 0; i < numFiles; ++i)
{
DebugPrintf("File[%d]: %s\n", i, files[i]);
}
/* Dispose the files - free each file and the array */
for (i = 0; i < numFiles; ++i)
{
InetFreeMemory (files[i]);
}
InetFreeMemory (files);
files = NULL;
}
InetFTPClose(ftpHandle);
return returnValue;

I have tried it with and without passive mode, and with and without changing the directory before hand. The computer executing the code is connected directly to the server through a crossover cable. The server is an embedded system running VxWorks. My CVI program has 2 threads, one is the main thread running the UI and the other is executing this code. Any help would be greatly appreciated.
0 Kudos
Message 1 of 5
(3,509 Views)
Hello,

I have had no trouble using your code to list the directory contents of "/" on ftp.ni.com

Is it possible for you to connect to another FTP server to test this code? I am not sure if this behavior is related to your system configuration, or if it is something specific to your VxWorks FTP server.

If this does work on another FTP server, is it possible that your VxWorks FTP server only implements a subset of FTP commands?

Scott Y
NI
0 Kudos
Message 2 of 5
(3,503 Views)
Ok, I did some packet sniffing and realized that the InetFTPGetDirList command sends the following to the FTP server: "NLST -aF" The DOS ftp program only sends "NLST" for an ls command. You were correct in suggesting that the VxWorks FTP server does not support the "NLST -aF" command. So I guess my question really is how to I get the InetFTPGetDirList to send only "NLST"? Or is there a way to send low level FTP commands without having to write my own FTP client program? Thanks.

Vahid
0 Kudos
Message 3 of 5
(3,499 Views)
Unfortunately there is no way to modify the behavior of the FTP commands. The best option at this time will be for you to implement your own FTP client that will allow you to send the specific command expected by your FTP server.

If you like you can create a product suggestion for this feature by clicking on the feedback link on the Contact NI web page.

Scott Y
NI
0 Kudos
Message 4 of 5
(3,485 Views)

You can use the functions:

InetFTPCommand (ftp_handle, "NLST", 0, 0, FTPCallback);

static int CVICALLBACK FTPCallback(int ftpHandle, int replyCode)
{

char buffer[1024];
int error;

while (1)
{

/* read data from server */
error = InetFTPReceiveData(ftpHandle, buffer, sizeof(buffer) - 1);

/* if error occurred return the error */
if (error < 0)
 return error;

/* stop reading if there is no more data */
if (error == 0)
 break;

/* NUL-terminate the buffer and print the data */
buffer[error] = '\0';
printf(buffer);

}

return 0;

}

 

0 Kudos
Message 5 of 5
(2,820 Views)