求从ftp下载文件源代码?
********说明:下面的代码能正常连接ftp,但总是下载失败,敬请帮忙分析一下*********
Clea
* lAccessType - some values
#Define INTERNET_INVALID_PORT_NUMBER 0
#Define INTERNET_OPEN_TYPE_DIRECT 1
#Define INTERNET_OPEN_TYPE_PROXY 3
#Define INTERNET_DEFAULT_FTP_PORT 21
* lFlags: only a few
#Define INTERNET_FLAG_ASYNC 268435456 && &H10000000
#Define INTERNET_FLAG_FROM_CACHE 16777216 && &H1000000
#Define INTERNET_FLAG_OFFLINE 16777216
#Define INTERNET_FLAG_CACHE_IF_NET_FAIL 65536 && &H10000
* registry access settings
#Define INTERNET_OPEN_TYPE_PRECONFIG 0
#Define FTP_TRANSFER_TYPE_ASCII 1
#Define FTP_TRANSFER_TYPE_BINARY 2
* type of service to access
#Define INTERNET_SERVICE_FTP 1
#Define INTERNET_SERVICE_GOPHER 2
#Define INTERNET_SERVICE_HTTP 3
* file attributes
#Define FILE_ATTRIBUTE_NORMAL 128 && 0x00000080
Declare INTEGER InternetOpen IN wininet;
STRING sAgent, INTEGER lAccessType, STRING sProxyName,;
STRING sProxyBypass, STRING lFlags
Declare INTEGER InternetCloseHandle IN wininet INTEGER hInet
Declare INTEGER InternetConnect IN wininet;
INTEGER hInternetSession, STRING sServerName,;
INTEGER nServerPort, STRING sUsername,;
STRING sPassword, INTEGER lService,;
INTEGER lFlags, INTEGER lContext
Declare INTEGER FtpGetFile IN wininet;
INTEGER hFtpSession, STRING lpszRemoteFile,;
STRING lpszNewFile, INTEGER fFailIfExists,;
INTEGER dwFlagsAndAttributes,;
INTEGER dwFlags, INTEGER dwContext
* you are free to choose any name, say "John Dow"
* server-side variable $AGENT is the target
sAgent = "hongyu"
sProxyName = Chr(0) && I have no proxy
sProxyBypass = Chr(0) && so there is nothing to bypass
lFlags = 0 && no flags used
* initialize access to Inet functions
hOpen = InternetOpen (sAgent, INTERNET_OPEN_TYPE_DIRECT,;
sProxyName, sProxyBypass, lFlags)
If hOpen = 0
? "找不到库 WinInet.Dll 的入口"
Return
Else
? "Wininet 句柄: " + LTRIM(STR(hOpen))
Endif
* connection parameters - you better put your data
strHost = "121.42.122.244"
strUser = "qxu1649560463"
strPwd = "su6683111"
* connecting to the FTP
hFtpSession = InternetConnect (hOpen, strHost,;
INTERNET_INVALID_PORT_NUMBER,;
strUser, strPwd,;
INTERNET_SERVICE_FTP, 0, 0)
If hFtpSession = 0
* close access to Inet functions and exit
= InternetCloseHandle (hOpen)
? "FTP " + strHost + " 无效"
Return
Else
? "连接到 " + strHost + " as: [" + strUser + ", *****]"
? "FTP 连接句柄: " + LTRIM(STR(hFtpSession))
Endif
* downloading a file from the FTP
* no check whether the target file exists
lpszRemoteFile = "myfolder/test" && if it still exists
lpszNewFile = "d:" && check the destination folder
fFailIfExists = 0 && do not stop if the target already exists
dwContext = 0
lnResult = FtpGetFile (hFtpSession, lpszRemoteFile, lpszNewFile,;
fFailIfExists, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_ASCII,;
dwContext)
If lnResult # 1
? "下载文件失败!"
Endif
* close handles
= InternetCloseHandle (hFtpSession)
= InternetCloseHandle (hOpen)
Return && main