byteboy11
asked on
Changing directories with FtpSetCurrentDirectory
I'm having a problem using this Microsoft WinInet function in my PB Code. Here is what's happening:
I successfully FTP into a server with that has 2 subfolders under the root, lets call the 2 subfolders Images and Items so it looks like this:
//(Root where I'm at after first FTP'ing in)
Images Folder
Items Folder
I can use FtpSetCurrentDirectoryA to go to the Items folder then I FTP some data, that works. The problem is how do I change to the Images folder from the Items folder??. I cant go directly to the folder and I cant seem to figure out how to go up one level or go to the root. I've tried calling my function like this while in the Items folder:
li_rc = FtpSetCurrentDirectoryA( iul_service, 'Images' ) == Return code error
li_rc = FtpSetCurrentDirectoryA( iul_service, ' ..' ) == Tried Space + period + period to go up one directory still get error.
Of course If I completly disconnect then reconnect to the server I'm placed in the root and I can then go there but I shouldn't have to disconnect from the FTP and come back in just to go to a different directory.
I thought if maybe I use FtpGetCurrentDirectoryA when I first come in maybe I can read the name of the root directory so I can know the name to pass to FtpSetCurrentDirectoryA later on but I can't get this function to work. Here is my code that calls this function but I keep getting an error saying %s Invalid Parameter or something when I call it, here is my code for that.
Integer li_rc
String ls_dir, ls_dir2
Ulong lul_mode
Boolean lb_rtn
CONSTANT uint MAX_PATH = 254
lul_mode = MAX_PATH
lb_rtn = FtpGetCurrentDirectoryA( iul_service,ls_dir,lul_mod e)
iul_errorcode = GetLastError()
IF NOT lb_rtn THEN
RETURN "-1"
ELSE
RETURN ls_dir
END IF
Prototypes for both functions:
FUNCTION ulong FtpSetCurrentDirectoryA( ulong hService, string szPath ) LIBRARY "wininet.dll" alias for "FtpSetCurrentDirectoryA;A nsi"
FUNCTION boolean FtpGetCurrentDirectoryA( ulong hService, string szCurrentDirectory, ulong dwCurrentDirectory) LIBRARY "wininet.dll" alias for "FtpGetCurrentDirectoryA;A nsi"
I successfully FTP into a server with that has 2 subfolders under the root, lets call the 2 subfolders Images and Items so it looks like this:
//(Root where I'm at after first FTP'ing in)
Images Folder
Items Folder
I can use FtpSetCurrentDirectoryA to go to the Items folder then I FTP some data, that works. The problem is how do I change to the Images folder from the Items folder??. I cant go directly to the folder and I cant seem to figure out how to go up one level or go to the root. I've tried calling my function like this while in the Items folder:
li_rc = FtpSetCurrentDirectoryA( iul_service, 'Images' ) == Return code error
li_rc = FtpSetCurrentDirectoryA( iul_service, ' ..' ) == Tried Space + period + period to go up one directory still get error.
Of course If I completly disconnect then reconnect to the server I'm placed in the root and I can then go there but I shouldn't have to disconnect from the FTP and come back in just to go to a different directory.
I thought if maybe I use FtpGetCurrentDirectoryA when I first come in maybe I can read the name of the root directory so I can know the name to pass to FtpSetCurrentDirectoryA later on but I can't get this function to work. Here is my code that calls this function but I keep getting an error saying %s Invalid Parameter or something when I call it, here is my code for that.
Integer li_rc
String ls_dir, ls_dir2
Ulong lul_mode
Boolean lb_rtn
CONSTANT uint MAX_PATH = 254
lul_mode = MAX_PATH
lb_rtn = FtpGetCurrentDirectoryA( iul_service,ls_dir,lul_mod
iul_errorcode = GetLastError()
IF NOT lb_rtn THEN
RETURN "-1"
ELSE
RETURN ls_dir
END IF
Prototypes for both functions:
FUNCTION ulong FtpSetCurrentDirectoryA( ulong hService, string szPath ) LIBRARY "wininet.dll" alias for "FtpSetCurrentDirectoryA;A
FUNCTION boolean FtpGetCurrentDirectoryA( ulong hService, string szCurrentDirectory, ulong dwCurrentDirectory) LIBRARY "wininet.dll" alias for "FtpGetCurrentDirectoryA;A
ASKER
I added ls_dir = space(1000)
I'm still getting Error: Error calling external function %s at line 30 in function of_getcurrentdirectory of object n_cst_wininet.
Now it looks like this:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------
Integer li_rc
String ls_dir
Ulong lul_mode
Boolean lb_rtn
CONSTANT uint MAX_PATH = 254
lul_mode = MAX_PATH
ls_dir = space(1000)
lb_rtn = FtpGetCurrentDirectoryA( iul_service,ls_dir,lul_mod e)
iul_errorcode = GetLastError()
IF NOT lb_rtn THEN
RETURN "-1"
ELSE
RETURN ls_dir
END IF
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ------
What should MAX_PATH be defined as? The MS Doc here doesnt say how to declare it:
http://msdn.microsoft.com/en-us/library/aa384153(VS.85).aspx
I'm still getting Error: Error calling external function %s at line 30 in function of_getcurrentdirectory of object n_cst_wininet.
Now it looks like this:
--------------------------
Integer li_rc
String ls_dir
Ulong lul_mode
Boolean lb_rtn
CONSTANT uint MAX_PATH = 254
lul_mode = MAX_PATH
ls_dir = space(1000)
lb_rtn = FtpGetCurrentDirectoryA( iul_service,ls_dir,lul_mod
iul_errorcode = GetLastError()
IF NOT lb_rtn THEN
RETURN "-1"
ELSE
RETURN ls_dir
END IF
--------------------------
What should MAX_PATH be defined as? The MS Doc here doesnt say how to declare it:
http://msdn.microsoft.com/en-us/library/aa384153(VS.85).aspx
What is the line 30 in of_getcurrentdirectory ?
try this
CONSTANT uint MAX_PATH = 260
lul_mode = MAX_PATH
ls_dir = space(MAX_PATH)
Try with some more large values for MAX_PATH if your directory path is suppose to be long. i.e 500, 1000 etc.
Regards,
Sandeep
try this
CONSTANT uint MAX_PATH = 260
lul_mode = MAX_PATH
ls_dir = space(MAX_PATH)
Try with some more large values for MAX_PATH if your directory path is suppose to be long. i.e 500, 1000 etc.
Regards,
Sandeep
ASKER
There were comments at the top so I removed them, now the error says line 11. Of course when I debug it does error out on the line that calls the external function so I know its failing there.
Basically I'm still getting the same error. It's like the function isn't defined or something, the parameters seem correct. I checked my version of wininet.dll and it's last modified on 12/07 so it's a fairly recent version of wininet.dll.
-------------------------- ---------- ---------- ---------- --------
Integer li_rc
String ls_dir
uint lul_mode
Boolean lb_rtn
CONSTANT uint MAX_PATH = 260
lul_mode = MAX_PATH
ls_dir = space(MAX_PATH)
lb_rtn = FtpGetCurrentDirectoryA( iul_service,ls_dir,lul_mod e)
iul_errorcode = GetLastError()
IF NOT lb_rtn THEN
RETURN "-1"
ELSE
RETURN ls_dir
END IF
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------
Basically I'm still getting the same error. It's like the function isn't defined or something, the parameters seem correct. I checked my version of wininet.dll and it's last modified on 12/07 so it's a fairly recent version of wininet.dll.
--------------------------
Integer li_rc
String ls_dir
uint lul_mode
Boolean lb_rtn
CONSTANT uint MAX_PATH = 260
lul_mode = MAX_PATH
ls_dir = space(MAX_PATH)
lb_rtn = FtpGetCurrentDirectoryA( iul_service,ls_dir,lul_mod
iul_errorcode = GetLastError()
IF NOT lb_rtn THEN
RETURN "-1"
ELSE
RETURN ls_dir
END IF
--------------------------
why don't you try once with the declaration i gave?
and use FtpGetCurrentDirectory instead of FtpGetCurrentDirectoryA.
As FtpSetCurrentDirectoryA is working fine, this also should work but still try once.
and use FtpGetCurrentDirectory instead of FtpGetCurrentDirectoryA.
As FtpSetCurrentDirectoryA is working fine, this also should work but still try once.
ASKER
Here is the code now, when I try to compile I get this error :
*Error C0116: Reference argument type does not match function definition: ftpgetcurrentdirectory
-------------------------- ---------- ---------- --------
Integer li_rc
String ls_dir
uint lul_mode
Boolean lb_rtn
ulong ul_temp
CONSTANT uint MAX_PATH = 500
lul_mode = MAX_PATH
ls_dir = space(MAX_PATH)
lb_rtn = FtpGetCurrentDirectory( iul_service,ls_dir,lul_mod e)
iul_errorcode = GetLastError()
IF NOT lb_rtn THEN
RETURN "-1"
ELSE
RETURN ls_dir
END IF
-------------------------- ---------- ---------- ---------- ---------- ---------- --------
local external function:
Function boolean FtpGetCurrentDirectory (ulong hConnect, ref string lpszCurrentDirectory, ref ulong lpdwCurrentDirectory) Library "WININET.DLL" Alias for "FtpGetCurrentDirectoryA;A nsi"
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------
*Error C0116: Reference argument type does not match function definition: ftpgetcurrentdirectory
--------------------------
Integer li_rc
String ls_dir
uint lul_mode
Boolean lb_rtn
ulong ul_temp
CONSTANT uint MAX_PATH = 500
lul_mode = MAX_PATH
ls_dir = space(MAX_PATH)
lb_rtn = FtpGetCurrentDirectory( iul_service,ls_dir,lul_mod
iul_errorcode = GetLastError()
IF NOT lb_rtn THEN
RETURN "-1"
ELSE
RETURN ls_dir
END IF
--------------------------
local external function:
Function boolean FtpGetCurrentDirectory (ulong hConnect, ref string lpszCurrentDirectory, ref ulong lpdwCurrentDirectory) Library "WININET.DLL" Alias for "FtpGetCurrentDirectoryA;A
--------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
and yes you can use FtpGetCurrentDirectoryA also as this name is alias for "FtpGetCurrentDirectoryA" as per defination
so sorry about that just you need to add "ref" keyword in declaration.
so sorry about that just you need to add "ref" keyword in declaration.
ASKER
It worked! Declaring it without the 'A' seemed to be the problem. Thanks a lot!
ASKER
Got it, so 'ref' was all that was really needed. I gotta make sure the PB definition matches the MS definition. Thanks again for pointing that out.
Function boolean FtpSetCurrentDirectory (ulong hConnect, ref string lpszDirectory) Library "WININET.DLL" Alias for "FtpSetCurrentDirectoryA;A
Function boolean FtpGetCurrentDirectory (ulong hConnect, ref string lpszCurrentDirectory, ref ulong lpdwCurrentDirectory) Library "WININET.DLL" Alias for "FtpGetCurrentDirectoryA;A
if you notice some variables are passed as reference and when you pass string as reference you need to assign memory to those variable before passing.
You can do this by
ls_dir = space(1000) // this is as per requirement.
Hope this will solve problem.
Regards,
Sandeep