West Wind Internet and Client Tools
wwsftp.ftplistfile object reference not set to an instance of an object
Gravatar is a globally recognized avatar based on your email address. wwsftp.ftplistfile object reference not set to an instance of an object
  VFPJCOOK
  All
  Dec 9, 2020 @ 12:49pm

Rick, I created a simple program to find out why I am getting an error when using wwsftp to pull a list of the files in a directory.

SET PROCEDURE TO "c:\vfe2005\dev\itf\wwsftp.prg"

SET STEP on
DO wwsftp

loFtp = CREATEOBJECT("wwSFTP")
loFtp.nFtpPort = 22

lcHost = "xxx.xxx.xxx.xxx" && Not sending the real ip address for security reasons
lcuserid= "apsoarmms"
lcpassword = "APSOTru$tFu5d!@cfs.com"

IF NOT VARTYPE(loFtp)=="O"
   RETURN .f.
ENDIF

lnhndlLogDebugFTPStuff=FCREATE(".\TEMP\ITFCOM001_Log_DebugFTPStuff.txt")
FPUTS(lnhndlLogDebugFTPStuff,"loFTP is an object.")

lnResult = loFtp.FtpGetFile(lcHost,"resync-12092020071546.arm","c:\apso\fromjms\itf-apso\resync-12092020071546.arm",1,lcuserid,lcpassword)
IF (lnResult != 0)
   ? loFtp.cErrorMsg
ENDIF

loFiles = loFtp.FtpListFiles("")  && or: "/subfolder" or "subfolder2" (relative)
IF NOT VARTYPE(lofiles)="O"
   && dont proceed because there are no files
   &&loFTP.release()
   && why did i not use ftpclose?
   &&loFtp.FtpClose()
   loFTP.destroy()
   loFtp= .null.
   RELEASE loFTP
   FPUTS(lnhndlLogDebugFTPStuff,"loFiles is NOT an object")
   FCLOSE(lnhndlLogDebugFTPStuff)
   RETURN .f.
ENDIF

Everything works perfect until the call to FtpListFiles. I get:

Where do I start to look for the reason for this error? Thanks, John

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  Rick Strahl
  VFPJCOOK
  Dec 9, 2020 @ 04:35pm

You need to open the connection when using FtpListFiles().

It might be confusing because FtpGetFile() and FtpSendFile() work without a call to FtpConnect() as they are self-contained routines that open a connection receive or send the file and then close the connection.

All other commmands work with an open connection using FtpConnect() as you can run multiple commands on a single connection.

Look at the example here:

wwSFTP::FtpListFiles()

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  VFPJCOOK
  Rick Strahl
  Dec 10, 2020 @ 04:15am

When I saw your response I thought "that's easy and sounds logical". Well, nothing is ever easy.

I did as you asked. Now I get an error on the call to loFtp.FtpConnect. File 'isnullorempty.prg' does not exist.

I dug around and found that function is in wwutils.prg so I modified my set procedure command to also include wwutils.prg

It still can not find the isnullorempty.prg so I am lost.

Also, the example you sent wwSFTP::FtpListFiles() is creating an object wwFTP rather than wwSFTP which is what I am creating. Perhaps it is going over my head but that could have something to do with my issue?

Thanks, John

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  Rick Strahl
  VFPJCOOK
  Dec 10, 2020 @ 12:02pm

ISNULLOREMPTY() is a function in wwUtils.prg. It's somewhat recent so maybe you're not using the latest version of that file...

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  VFPJCOOK
  Rick Strahl
  Dec 11, 2020 @ 10:08am

The function isnullorempty is in my wwutils.prg

Here is modified test program:

SET PROCEDURE TO "c:\vfe2005\dev\itf\wwsftp.prg", "c:\vfe2005\dev\itf\wwutils.prg"

SET STEP on
DO wwsftp

loFtp = CREATEOBJECT("wwSFTP")
loFtp.nFtpPort = 22

lcHost = "xxx.xxx.xxx.xxx" && not sending ip for security reasons
lcuserid= "apsoarmms"
lcpassword = "APSOTru$tFu5d!@cfs.com"

IF NOT VARTYPE(loFtp)=="O"
   RETURN .f.
ENDIF

lnhndlLogDebugFTPStuff=FCREATE(".\TEMP\ITFCOM001_Log_DebugFTPStuff.txt")
FPUTS(lnhndlLogDebugFTPStuff,"loFTP is an object.")

lnResult = loFtp.FtpGetFile(lcHost,"resync-12092020071546.arm","c:\apso\fromjms\itf-apso\resync-12092020071546.arm",1,lcuserid,lcpassword)
IF (lnResult != 0)
   ? loFtp.cErrorMsg
ENDIF

loFtp.FtpConnect(lchost,lcuserid,lcpassword)
loFiles = loFtp.FtpListFiles("")  && or: "/subfolder" or "subfolder2" (relative)
loFtp.FtpClose()
IF NOT VARTYPE(lofiles)="O"
   && dont proceed because there are no files
   &&loFTP.release()
   && why did i not use ftpclose?
   &&loFtp.FtpClose()
   loFTP.destroy()
   loFtp= .null.
   RELEASE loFTP
   FPUTS(lnhndlLogDebugFTPStuff,"loFiles is NOT an object")
   FCLOSE(lnhndlLogDebugFTPStuff)
   RETURN .f.
ENDIF

llvaluetoreturn=.f.
FOR EACH loFile IN loFiles FOXOBJECT
   FPUTS(lnhndlLogDebugFTPStuff,ALLTRIM(lofile.name))
   lnResult = loFtp.FtpGetFile(lchost,ALLTRIM(loFile.Name),"c:\apso\fromjms\itf-apso\tmpprocessing\"+ALLTRIM(lofile.name),1,lcuserid,lcpassword)
   IF lnResult=0
      FPUTS(lnhndlLogDebugFTPStuff,ALLTRIM(lofile.name)+"did the ftpget")
      loFtp.FtpDeleteFile(".\"+ALLTRIM(lofile.name))
      llvaluetoreturn=.t.
   ELSE
      FPUTS(lnhndlLogDebugFTPStuff,ALLTRIM(lofile.name)+"ftpget was not sucessful")
   ENDIF
ENDFOR
&& you got everything from the ftp server and copied it to the subfolder for processing and you deleted them from the ftp server.
&& now i need to move them to the normal folder but doing so oldest first copying the data file and then the associated ready file.
&& Then after all that delete everything in the processing folder.
&& One more safety - may not want to copy any file from the processing folder into the normal folder if it is older than the last file we copied to the normal folder.
&& probably have to put the datetime of the files in a text file and as I copy them check against that file to see if it is newer or something.......
FCLOSE(lnhndlLogDebugFTPStuff)
RETURN llvaluetoreturn

I get the following error when stepping thru the code at loFtp.FtpConnect(lchost,lcuserid,lcpassword):

Keep in mind that when I am writing programs like this test program, I am working outside my "normal" environment of Visual FoxExpress so things like SET PROCEDURE TO are not something that comes natural to me. I am using the copy of wwutils.prg that shipped with my copy of webconnection. It is dated 1/6/20 and again, it DOES contain the function isnullorempty. I used GoFish and searched for all instances of isnullorempty thinking maybe there is another something that is messing me up. The one in wwutils.prg is the ONLY one located.

Thanks, John

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  Rick Strahl
  VFPJCOOK
  Dec 11, 2020 @ 11:26am

Make sure the right version of wwUtils.prg is in your path. If it's loaded and ISNULLOREMPTY() can't be found, then some other version is getting loaded.

DO wwSFTP should load all dependencies including wwUtils (which is loaded as part of wwFtp.prg).

When in doubt check:

SET("PROCEDURE")

and look for the wwUtils entry.

And recompile your code just in case you had an old version.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  VFPJCOOK
  Rick Strahl
  Dec 12, 2020 @ 05:46am

Rick, I feel really stupid. I have spent several hours looking for old versions of wwutils and trying many things. I have come across something that I believe I must figure out before I will ever find the issue.

I am in the VFP command window. I issue set default to c:\vfe2005\dev\itf (which is a valid directory). Then I issue ?set("default"). Foxpro tells me the value is C: so of course that is telling me that my set default command is not doing anything.

I have tried set default to "c:\vfe2005\dev\itf". I tried cd to c:\vfe2005\dev\itf which works and then using SYS(5)+SYS(2003) which pulls the current directory correctly. I tried putting the path in a variable and with and without the &.

Obviously I do not understand how SET DEFAULT works. I feel like I just set myself back 30 years. Any insight appreciated.

Thanks, John

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  Tore Bleken
  VFPJCOOK
  Dec 12, 2020 @ 06:30am

?Set("Default") will only show the drive. Try ?FullPath(Set("Default")).

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  Rick Strahl
  VFPJCOOK
  Dec 12, 2020 @ 01:19pm

SET DEFAULT() doesn't tell you anything useful. You need to use SET("PROCEDURE") and look where things are loading from. That command will tell you:

  • Whether wwUtils is loaded at all
  • Where it was loaded from

Make sure you don't have something in your code that does SET PROCEDURE TO without an ADDITIVE clause which will wipe out all loaded libraries.

What matters is not the DEFAULT but the PATH.

Make sure that wwUtils.prg exists and that it has a ISNULLOREMPTY() function.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  VFPJCOOK
  Rick Strahl
  Dec 13, 2020 @ 04:41am

Still, no luck.

I need to make this as simple as possible. New test program:

set step on
SET PROCEDURE TO "c:\vfe2005\dev\itf\wwutils.prg", "c:\vfe2005\dev\itf\wwsftp.prg"
?set("PROCEDURE")
lctestvar="johncook"
llretval=isnullorempty(lctestvar)

The ?set("PROCEDURE") command sends the following to my main visual foxpro window:

I get the foxpro error, file 'isnullorempty.prg' does not exist.

About the only thing that I see that may not look right is the value returned by set("PROCEDURE"). Notice the wwutils.fxp does not have any path yet the wwsftp.fxp does. That may be a clue. I am working out of the c:\vfe2005\dev\itf folder. As best I can tell there is no way that I could be using anything except what is in that folder. That folder contains both wwutils and wwsftp both of which I recompiled in the last few minutes.

I tried to add a code snippet containing my whole wwutils.prg but it is obviously to large. Instead, just to prove that my wwutils.prg DOES contain the isnullorempty function, I cut and pasted that function from my wwutils.prg:

************************************************************************
*  IsNullOrEmpty
****************************************
***  Function: Returns whether a value is null or Empty
***    Assume:
***      Pass: lvValue - value 
***    Return: .T. or .F.
************************************************************************
FUNCTION IsNullOrEmpty(lvValue,llCheckArray)

IF llCheckArray
	lcType = TYPE("lvValue")
	IF lcType = "A"
	   RETURN .T.
	ENDIF
ENDIF 

lcType = VARTYPE(lvValue)

IF lcType = "X" OR lcType = "U"
   RETURN .T.
ENDIF   
  
IF INLIST(lcType,"C","M","N","Y","D","T","L") AND EMPTY(lvValue)
   RETURN .T.
ENDIF

RETURN .F.  
ENDFUNC
*   IsNullOrEmpty

Totally bluffed, John

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  Rick Strahl
  VFPJCOOK
  Dec 13, 2020 @ 01:38pm

Look in the file and make sure the function is actually in there... and recompile your PRG files.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  VFPJCOOK
  Rick Strahl
  Dec 15, 2020 @ 08:12am

OK, I have looked at that 300 times and Yes, the function isnullorempty is in my wwutils.prg and I have recompiled it many times but still when I run my test program I get the error isnullorempty.prg does not exist.

I can only conclude that even though I have set procedure to my wwutils.prg and everything is in the directory from which I am working, that does not mean VFP can locate the function. I tried making a call to a different wwutils function File2Var. I get the same error.

I need to get this finished. Can I hire you to connect to my computer and take a look please?

Thanks, John

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  Tore Bleken
  VFPJCOOK
  Dec 15, 2020 @ 09:20am

Remember that if you have a Set Procedure somewhere in your code, and this line does not include the Additive keyword, all previously 'values' will be removed from the list.

The same goes for Set Path, Set Library and Set Classlib.

In the debugger, add Set('Procedure') and Set('path') to the Watch window

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  VFPJCOOK
  Tore Bleken
  Dec 15, 2020 @ 02:00pm

Hi Tore,

The whole program is only 5 lines. I am in the VFP command window. I do a cd to c:\vfe2005\dev\itf. The following program and wwutils.prg are all in the current directory.

set step on
SET PROCEDURE TO "c:\vfe2005\dev\itf\wwutils.prg", "c:\vfe2005\dev\itf\wwsftp.prg"
?set("PROCEDURE")
lctestvar="johncook"
llretval=isnullorempty(lctestvar)
return

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  VFPJCOOK
  VFPJCOOK
  Dec 15, 2020 @ 03:06pm

OK, I have more information.

start VFP from the command window: cd c:\vfe2005\dev\itf set procedure to "c:\vfe2005\dev\itf\wwutils.prg" ?set("procedure") The above displays this in the main screen: C:\VFE\DEV\ITF\WWUTILS.FXP lctestvar="jc" ?isnullorempty(lctestvar) The above displays .F. in the main screen. YEA! That works perfectly.

Now put the same exact commands in a test.prg. Compile the prg and do the prg. I get an error, 'isnullorempty.prg' is not found. Besides getting the error, the only other thing that is different is when the ?set("procedure") is issued from test.prg it displays simply WWUTILS.FXP without the path. That has to be a clue.

Thanks, John

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  Rick Strahl
  VFPJCOOK
  Dec 16, 2020 @ 11:43am

You delete all your FXP files. And if you're running a project, recompile the project.

That just looks like you likely have an old file.

Either way this is an environment problem on your end - it sounds like you have paths that point to multiple potentially different copies of the West Wind libraries. Make sure you don't have more than one version along your FoxPro path. When in doubt always delete all FXP files and try again (or recompile a project file if that's what you're running).

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  VFPJCOOK
  Rick Strahl
  Dec 16, 2020 @ 02:04pm

You are correct in saying that I have an environment issue on my end. You are also correct in saying it acts like I am looking at an old fxp file. I came to those same conclusions.

I copied wwutils.prg to wwutils-copy.prg, changed my set procedure to use it instead and it works perfectly. That also would indicate I am accessing some old copy of wwutils.

I have removed all old fxp's. I even looked in windows registry thinking somehow windows was using that to know what copy of wwutils to use. I am not going to figure this out. The one clue that is persistent across all attempts is ?set("procedure") returns wwutils.fxp when it does NOT work and it returns c:\vfe2005\dev\itf\wwutils.fxp when it DOES work.

I have given up on figuring this out. I am confident it will work when I include the wwutils and wwsftp in my project, build an executable and run the exe which is all I need to do. The only time it does not work is when doing this from a simple compiled prg.

Thanks, John

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  Tore Bleken
  VFPJCOOK
  Dec 16, 2020 @ 09:03pm

I have made it a habit to regularly delete all .fxp files from all my folders.

Gravatar is a globally recognized avatar based on your email address. re: wwsftp.ftplistfile object reference not set to an instance of an object
  Rick Strahl
  VFPJCOOK
  Dec 16, 2020 @ 10:04pm

wwUtils.fxp means it's being loaded out of an .app or .exe file most likely. Full path means it's loading from disk.

If it's in your project (which it seems to be) double check and make sure the PRG file in the project points at the right file!

+++ Rick ---

© 1996-2024