VFP Determin If Internet Folder Exists

Hi all. I'm trying to find a way using VFP9 to determine if a folder on a remote Internet server exists - for example google.com/stuff

I have a function (GetFileSizeViaHTPP) from SPS that I've been hacking away at in an attempt to force it to do what I want but without success.

The need arises from a routine that creates directories on a server via FTP. The problem is I currently have no way to verify that they have in fact been created...
formadmirerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pcelbaCommented:
You should clarify what is the possible access method to this folder (HTTP, FTP, SFTP, ...) then we may offer a method to check this folder. Also you should specify what access do you need to this folder (read/only, read/write).

Option are:
1) List folder contents - if error occurs the folder does not exist or is not accessible
2) Create a file in given folder - if error occurs the folder does not exist or is not accessible for write access
3) Create the folder twice. If error occurs the second time the folder exists.
etc.
0
formadmirerAuthor Commented:
The folder is being created via FTP using vfpconnection.fll.

I don't need the ability to list the folder contents, create a file within the folder or anything similar. I just need to verify that the folder itself was actually created.

As it is now there are occasions, for whatever reason, that the FTP routine fails to create the folder.
0
pcelbaCommented:
What returns the FTP routine when it fails?

The ability to list the folder MUST help.
You may use FTP to list the folder one level up and look at the result.
Or you may list the given folder and if no error occurs then the folder exists.

I wouldn't look for something special telling me "Yes, the folder exists".
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

formadmirerAuthor Commented:
When the creation fails it is typically the result of an invalid username and/or password combination, and not the fault of anything to do with the fll.

I suppose there could potentially be issues with firewalls, port blocks, etc., but all I really need is to verify that the folder was created, and if not, instruct the client to verify their username and password.

A couple of minutes ago I just started looking into doing the folder verification with msxml2.
0
pcelbaCommented:
This works for me:
Create FTP script (YourScriptFile.TXT) to list the folder contents:
op ftp.yourdomain.com
username
password
dir YourFolder
quit

Open in new window

and execute the DOS FTP command in FoxPro:

RUN FTP -s:YourScriptFile.TXT > YourOutPutFile.txt

And now read the output file YourOutPutFile.txt in VFP (e.g. by FILETOSTR() function call) and check the folder existence.

Dirty but reliable and easy... You may fine tune the script in CMD.EXE

(VFPCONNECTION is causing Insufficient memory error when passing more than one command and it is really not easy to obtain what you need sometimes...).
0
formadmirerAuthor Commented:
Here's what I've got so far. My output file is not being created, and I believe the issue lies with DOS FTP not liking my path to the ftpscript file.

The ftpscript file itself looks to be formatted correctly.
Can you offer any suggestions?

lcThisValue = lcDomain
lnLen = LEN(lcThisValue)
lcLastChar = SUBSTR(lcThisValue,lnLen, 1)
IF lcLastChar = "/" OR lcLastChar = "\"
	lcDomain = SUBSTR(lcThisValue,1, lnLen -1)
ENDIF

lcFile = "ftpscript.txt"
lcPathtoFile = pcTempData + lcFile
lcOutputFile = pcTempData + "directory_result.txt"

lcFileString = ;
'open ftp.' + lcDomain + CHR(13) + CHR(10) + ;
lcUser + CHR(13) + CHR(10) + ;
lcPass + CHR(13) + CHR(10) + ;
'dir ' + lcDirectory + CHR(13) + CHR(10) + ;
'quit'
TRY
	STRTOFILE(lcFileString, lcPathtoFile)
CATCH
	MESSAGEBOX("Not writable?", 0 + 48 + 0,"Directory Not Writable" )
ENDTRY

lcFTP = "RUN FTP -s:" + lcPathTofile + " > " + lcOutputFile
&lcFTP

IF ADIR(laGarbage,lcOutputFile)>0
	lcResult = FILETOSTR(lcOutputFile)
	IF ((lcDirectory) $ lcResult)
		WAIT WINDOW "SUCCESS"
	ELSE
		WAIT WINDOW "FAIL"
	ENDIF
ELSE
	WAIT WINDOW "output file does not exist"
ENDIF

Open in new window

0
pcelbaCommented:
Your folder/file name contains spaces probably so you have to enclose filenames into double quotes:

lcFTP = 'RUN FTP -s:"' + lcPathTofile + '" > "' + lcOutputFile + '"'
0
Olaf DoschkeSoftware DeveloperCommented:
msxml2? You're trying a GET http request? You can't ever determine the existance of a folder in a http request. If the URL you give is a folder, the default file is returned, and that normally is index.htm, index.html, index.asp, index.php etc. It's defined at the wed server level and there can be multiple default files, which are checked one after the other and you get a file not found status 404, if no default file can be found. And still doesn't tell you, if the folder exists or not.

Let's take it from the start: When you create a folder via ftp, the folder creation ftp command will already return success or fault.

Every FTP command you send returns a status code.

And the reason a MKD command fails can't be wrong credentials, as then a user would even not be able to connect, it can only be insufficient privileges to create a directory.

In terms of the vfpconnection fll make use of FTPCommands, populate an array with a single element with a single command, and the return value of .T. for success or .F. for failure tells you, what you want to know.

step 1: Try a CWD into the directory, to see, if it already exists.
If .T.: done, else step 2
step 2: Try a MKD,
If .T., else.insufficient rights.

Don't make it more complicated, then it needs to be.

Bye, Olaf.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
formadmirerAuthor Commented:
Got it to work. Just removed the path from my filenames and issued a CD before executing the DOS FTP.

the only issue now is that the DOS window hangs open and won't close without forcibly closing it.

Looks like it's not seeing the quit at the end.

I'll add the double-quotes as well, better safe than sorry.
0
pcelbaCommented:
Thanks to Olaf this works for me finally
DIMENSION aryFTPCommands(1)
aryFTPCommands(1) = "CWD MyTestedFolder/AndPossibleSubfolder"
?FTPCommands("FTP://usernae:password@ftp.doamin.com/", @aryFTPCommands)

Open in new window


The DOS FTP needs to list the folder one level up and then to check the result.

Does the DOS window hangs in FTP command utility or do you see the DOS prompt? My DOS window closes w/o problems.
0
formadmirerAuthor Commented:
The window is hanging in FTP as far as I know as I'm not seeing the "c" prompt. I even added a 'disconnect' and a 'bye' line hoping they would trigger a release - but nothing.


I'm going to give the code above a try now...
0
Olaf DoschkeSoftware DeveloperCommented:
With RUN FTP you don't just run ftp, you create a CMD.EXE window, and you quit FTP, but not that window, of course.

Above code of pavel is just step1, if the folder doesn't exist and the execution of CWD returns .F. of course you would want to execute MKD.

Bye, Olaf.
0
formadmirerAuthor Commented:
The code provided above does the job beautifully.

It's always difficult when it comes to closing out the question, for example in this case pcelba you worked with me from the very beginning and made numerous contributions, although it was ultimately olaf's suggestion that provided the answer. How does one 'score' that? Who do you award the best answer and how do you divide points??

I always want to be as fair as possible so usually I split the points evenly. Best answer's a little more tricky. Just know that if I don't get you on this one, I will on the next...

Thanks for all the help!!
0
pcelbaCommented:
Olaf should obtain 1/2 of points.

We could clarify when the DOS window closes in RUN FTP command.

Mine closes immediately after the QUIT when you execute RUN FTP and allow interactive FTP session.

But it depends on several settings like COMSPEC environment variable and FoxRUN.PIF file availability.  My COMSPEC points to Windows\System32\CMD.EXE  and the FoxRUN.PIF  is not available.

VFPCONNECTION.FLL would need several improvements and fixes. I hope author will make the source available sometimes...
0
Olaf DoschkeSoftware DeveloperCommented:
I agree, also about the FLL. It would also be nice to have sources of vfpcompression.fll. For example in my experience setting the compression doesn't change compression grade. I tried several files with it with all the compression levels and also with winzip or 7zip. vfpcompression stays with the normal compression level as it seem.

But anyway, this should be addressed to Craig Boyd, otherwise this won't change.

Bye, Olaf.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.