Truncated cFileName attribute when calling FtpFindFirstFile through VB

  • Dear Friends

    I am attempting to download data from an FTP server using VB; however the cFileName attribute of the WIN32_FIND_DATA structure returned by calling the FtpFindFirstFile function is returning only the final few characters of the filename. This prevents me from using the FtpGetFile function to download the file.

    The number of characters it returns is anywhere from two to eight. For instance, if the filename is filename.xlsx, the cFileName attribute — after trimming nulls — might give sx or ame.xlsx

    I have already spent quite a few weeks trying to crack this, including an extensive online search and trialling using different computers but to no avail. I am using a 64-bit Windows 10 Pro operating system.

    I have copied the simplest version of the code below, with the connection details obscured for sensitivity. Would anyone be able to help me please?



  • Well I've not done much with the API's you're using, actually never done anything. However, the issue is that because I don't have an FTP file to download I can't troubleshoot your code. Do you know of a FTP location that works that you can reference.

    Have you tried changing the constant max_path?
    What value is in the AlternateFileName variable?

  • Hi Barry

    Thanks for your reply and sorry for the delayed response

    I have tried virtually everything including changing MAX_PATH and using the AlternateFileName attribute

    Unfortunately I do not have an FTP server which I can share with you because the FTP server is run by our client and has sensitive information on it

    Best wishes


  • Try some of these routines. Note how nulls are trimmed.

    Free public ftp sites are hard to find these days. Look for ftpsearch and you can search for some. Simtelnet was one of the most mirrored sites at one time. Here is one you can try using. It looks like a file that I uploaded back in the 90's.…/win95/wpwin/

  • Hi Kenneth

    Thanks for your reply

    Actually the code that you posted is the code that I originally tried before my four weeks of labouring at getting the code to work! Thanks for your suggestion though.