Discussion:
FTP server - directory name has spaces
(too old to reply)
Dave Calkins
2006-05-27 12:23:01 UTC
Permalink
I'm attempting to find and remove a bunch of files from an FTP server which
match a specified pattern. The problem I'm having is that the directory on
the server contains a space in the name.

I'm using the MFC WinInet wrapper classes to make use of the API. So, my
code looks like the following:

CInternetSession inetSession;
CFtpConnection * pConnection = NULL;
pConnection =
inetSession.GetFtpConnection(oc->server,oc->userName,oc->password);
CFtpFileFind finder(pConnection);
CStringArray filesToDelete;
BOOL bWorking = finder.FindFile(oc->fileNames);
while (bWorking)
{
bWorking = finder.FindNextFile();
filesToDelete.Add(finder.GetFilePath());
}

What is the correct way to deal with this? I've tried using the following
as arguments to the FindFile() method which do not appear to work.

My?Stuff
My\ Stuff
My*Stuff
Dave Calkins
2006-05-30 20:44:01 UTC
Permalink
fyi, I discovered that the WinInet API called by the MFC classes for finding
files on an FTP server assumes no spaces in the file pattern argument
(according to the MSDN documentation for the API).

I've been able to work around the issue as follows. It turns out you can
change the working directory to a directory which contains spaces. So, I
pull off the directory portion of the string and change the working directory
to that directory. Once there, I use the find function on the file pattern.

For example, assuming the file pattern to remove looks like the below:

"/a/b/c/My Stuff/data*.exe"

I first change the working directory to "/a/b/c/My Stuff" and then use the
find on "data*.exe".

The limitation this workaround introduces is that the wildcards can only be
in the filename part not the directory path portion. So you can't do
"/a/b*/c/My Stuff/data*.exe", for example.
Post by Dave Calkins
I'm attempting to find and remove a bunch of files from an FTP server which
match a specified pattern. The problem I'm having is that the directory on
the server contains a space in the name.
I'm using the MFC WinInet wrapper classes to make use of the API. So, my
CInternetSession inetSession;
CFtpConnection * pConnection = NULL;
pConnection =
inetSession.GetFtpConnection(oc->server,oc->userName,oc->password);
CFtpFileFind finder(pConnection);
CStringArray filesToDelete;
BOOL bWorking = finder.FindFile(oc->fileNames);
while (bWorking)
{
bWorking = finder.FindNextFile();
filesToDelete.Add(finder.GetFilePath());
}
What is the correct way to deal with this? I've tried using the following
as arguments to the FindFile() method which do not appear to work.
My?Stuff
My\ Stuff
My*Stuff
Loading...