We help IT Professionals succeed at work.
Get Started

Changing directories with FtpSetCurrentDirectory

byteboy11
byteboy11 asked
on
2,182 Views
Last Modified: 2013-12-26
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_mode)
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;Ansi"

FUNCTION boolean FtpGetCurrentDirectoryA( ulong hService, string szCurrentDirectory, ulong dwCurrentDirectory) LIBRARY "wininet.dll" alias for "FtpGetCurrentDirectoryA;Ansi"









Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE