Downloading a file via FTP in VBA using wininet.dll not sending in ASCII
Im using the wininet.dll library to give some FTP functionality to my
Excel sheet.
Below is the ftpget function declaration. There is more to it, like
connecting to the FTP server but I have omitted that bit.
' Get a file using FTP
Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" _
(ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean
The code I have works in terms of downloading a file from the FTP server
by calling eg
RemoteFileStr = "filetoget.txt" ' file name on server, including directories
NewFileStr = "c:\filtetoget.txt" ' file name on MY system
FailIfExistsBool = False
FlagsAndAttributesLong = 128 ' Normal file, no special flags set.
FlagsLong = 1 ' FTP Transfer Type ASCII
ContextLong = 0 ' apparently not required.
FtpGetFile(MyFTPHandleLong, RemoteFileStr, NewFileStr, FailIfExistsBool,
FlagsAndAttributesLong, FlagsLong, ContextLong)
My problem is that the file is unreadable when I open it in notepad.
Using a proper ftp program and downloading the file in ASCII format it
works fine. But even though I have set the flag to force ASCII FlagsLong =
1, it seems to want to download it in binary format because it's all
symbols and glyphs and no english letters.
It also seems to ignore the FailIfExistsBool = False too, because if I
dont delete the file before I try again the FTP fails.
Any ideas on what is wrong?
Ref for ftpgetfile is below
http://msdn.microsoft.com/en-us/library/windows/desktop/aa384157(v=vs.85).aspx
No comments:
Post a Comment