views:

204

answers:

2

Hi,

I'm transferring a file using ftp in Delphi.

I am able to connect to the ftp account ok but when I try and upload a file the FtpOpenFile function returns nil instead of a handle the file to be uploaded.

hintfile := FtpOpenFile(hintconnect,PChar(tgtfn),GENERIC_WRITE,FTP_TRANSFER_TYPE_BINARY,0);

If I log into the ftp site using an ftp client application and exactly the same credentials I can upload the file without a problem.

Any suggestions appreciated.

+1  A: 

Try to get the last error, documentation says it all:

"Returns a handle if successful, or NULL otherwise. To retrieve a specific error message, call GetLastError."

http://msdn.microsoft.com/en-us/library/aa384166(VS.85).aspx

Bartosz Wójcik
A: 

Try adding INTERNET_FLAG_PASSIVE to your Internetopen call, see also

http://etutorials.org/Programming/Pocket+pc+network+programming/Chapter+2.+WinInet/File+Transfer+Protocol+FTP/

Marco van de Voort
Thanks Marco, that helped!
SamH