[Simh] FTP client connecting to SIMH/OpenVMS?

Vorländer, Martin MV at PDV-SYSTEME.DE
Thu Jun 12 02:52:57 EDT 2008


Peter,

> I'm struggling to get a simple client program running 
> on a PC to be able to FTP a file to/from OpenVMS 7.1 running 
> under SIMH. The issue is simple: the Microsoft .NET 2.0 FTP 
> class fesses-up when confronted with VMS directory names. It 
> basically doesn't work, and Microsoft have acknowledged this 
> as an issue.
> 
> I'm just wondering if anyone else on the list has solved this 
> problem, of how to write a simple Windows program to get 
> files in/out of VMS, using c# / DotNet etc.

No idea what the "Microsoft .NET 2.0 FTP class" looks like, but
here's something I wrote that uses the WinInet FTP functions
to get all files in a directory (beware of lines wrapping).

HTH,
  Martin


/*
Format of FtpFindFirstFile/InternetFindNextFile is the same as an FTP DIR, that is:

Ftp> dir sys$manager:decw*.com

Directory SYS$SYSROOT:[SYSMGR]

DECW$KILLSERVER0.COM;1	No privilege for attempted operation
DECW$PRIVATE_APPS_SETUP.COM;2	No privilege for attempted operation
DECW$PRIVATE_APPS_SETUP.COM;1	No privilege for attempted operation

Total of 3 files, 0/0 blocks

Directory SYS$COMMON:[SYSMGR]

DECW$CONSOLE.COM;1       3/3          29-MAR-2000 07:32:20  [FIELD,SYSTEM]         (RWED,RWED,RE,RE)
DECW$DEFAULT_DESKTOP.COM;1
                         1/3          29-JAN-2004 15:50:06  [FIELD,SYSTEM]         (RWED,RWED,RE,RE)
DECW$DEVICE.COM;1       56/57          1-OCT-2003 22:04:23  [FIELD,SYSTEM]         (RWED,RWED,RE,RE)
DECW$DEVICE_CONFIG_COMMON.COM;1
                         6/6           5-JAN-1994 13:08:13  [FIELD,SYSTEM]         (RWED,RWED,RE,RE)
...

Total of 30 files, 384/420 blocks

Grand total of 2 directories, 33 files, 384/420 blocks

Ftp>


except that blank lines are skipped.

*/
int GetFiles(HINTERNET hConnection, LPSTR pattern) {
  HINTERNET hFindFile = NULL;
  WIN32_FIND_DATA FindFileData;
  int rc = ERROR_SUCCESS;
  char fspec[_MAX_PATH],
       lastspec[_MAX_PATH] = "",
       *p;
  BOOL continuation_line = FALSE;

  hFindFile = FtpFindFirstFile(hConnection, "*.*", &FindFileData, INTERNET_FLAG_RELOAD, 0);
  if (! hFindFile)
    return(ProcessError("FindFirstFile"));

  do {
    if (verbosity > 2)
      fprintf(stderr, "  %s\n", FindFileData.cFileName);
    if (continuation_line) {
      continuation_line = FALSE;
      continue;
    }
    strcpy(fspec, FindFileData.cFileName);
    /*
    if (fspec[0] == ' ') // continuation line
      continue;
    */
    if (strncmp(fspec, "Directory ", sizeof("Directory ")) == 0) // directory line
      continue;
    if (strncmp(fspec, "Total of ", sizeof("Total of ")) == 0) // statistics line
      continue;
    if (strncmp(fspec, "Grand total of ", sizeof("Grand total of ")) == 0) // statistics line
      continue;
    if (strchr(fspec, ' ') == NULL) // no complete entry
      continuation_line = TRUE;
    _strupr(fspec);
    if ((p = strchr(fspec,';')) != NULL) // strip semicolon and everything after it
      *p = '\0';
    if (strcmp(fspec, lastspec) == 0) // multiple versions of the same file
      continue;
    strcpy(lastspec, fspec);
    if (strcmp(&fspec[strlen(fspec)-4], ".DIR") == 0) // sub-directory entry
      continue;
    if (! match(pattern, fspec)) // no match?
      continue;

    if (verbosity > 0)
      fprintf(stderr, "GETting file %s\n", fspec);

    if (!(opt & OPT_M_NOCOPY) && ! FtpGetFile(
      hConnection,      // connection handle
      fspec,          // remote file
      fspec,          // local file name
      FALSE,          // fail if exists?
      FILE_ATTRIBUTE_NORMAL,  // CreateFile() flags
      FTP_TRANSFER_TYPE_ASCII  // flags
      | INTERNET_FLAG_RELOAD,
      0            // context
    )) {
      rc = ProcessError("FtpGetFile");
      break;
    }
    strcat(fspec, ";"); // UCX FTP DEL needs a semicolon
    if (!(opt & OPT_M_NODELETE) && ! FtpDeleteFile(hConnection, fspec)) {
      rc = ProcessError("FtpDeleteFile");
      break;
    }
  }
  while (InternetFindNextFile(hFindFile, &FindFileData));

  if (rc == ERROR_SUCCESS && GetLastError() != ERROR_NO_MORE_FILES)
    ProcessError("InternetFindNextFile");

  InternetCloseHandle(hFindFile);

  return(rc);
}

-- 
 O Lord, won't you buy me     | Martin Vorlaender  |  OpenVMS rules!
 an HP OS                     | work: mv at pdv-systeme.de
 its name starts with "Open"  |   http://vms.pdv-systeme.de/users/martinv/
 and ends in "VMS" ...        | home: martin.vorlaender at t-online.de       



More information about the Simh mailing list