标题:分析从ftp下载文件失败原因?已经是第二次发贴了。
取消只看楼主
su0527
Rank: 2
等 级:论坛游民
帖 子:452
专家分:79
注 册:2015-1-10
结帖率:96.03%
已结贴  问题点数:20 回复次数:6 
分析从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.txt"        && if it still exists
lpszNewFile    = "d:\myfolder"    && 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



[此贴子已经被作者于2017-9-18 18:34编辑过]

搜索更多相关主题的帖子: ftp Define INTEGER STRING the 
2017-09-17 15:06
su0527
Rank: 2
等 级:论坛游民
帖 子:452
专家分:79
注 册:2015-1-10
得分:0 
回复 2楼 吹水佬
改为:lpszRemoteFile = "myfolder/text"
结果还是下载失败。
2017-09-18 06:34
su0527
Rank: 2
等 级:论坛游民
帖 子:452
专家分:79
注 册:2015-1-10
得分:0 
回复 4楼 吹水佬
在IE中打开没有问题。

text改成test之后结果一样:下载文件失败!


[此贴子已经被作者于2017-9-18 18:37编辑过]

2017-09-18 18:35
su0527
Rank: 2
等 级:论坛游民
帖 子:452
专家分:79
注 册:2015-1-10
得分:0 
回复 5楼 kim_wei
试用过,一样没有成功。
2017-09-18 18:38
su0527
Rank: 2
等 级:论坛游民
帖 子:452
专家分:79
注 册:2015-1-10
得分:0 
回复 9楼 厨师王德榜
按照您所说修改后,仍是:下载文件失败!真不知道是为什么?
2017-09-19 14:48
su0527
Rank: 2
等 级:论坛游民
帖 子:452
专家分:79
注 册:2015-1-10
得分:0 
回复 11楼 吹水佬
错误信息是拒绝访问,如何能获得这个权限?
2017-09-19 16:44
su0527
Rank: 2
等 级:论坛游民
帖 子:452
专家分:79
注 册:2015-1-10
得分:0 
回复 13楼 吹水佬
谢谢,再试试
2017-09-20 07:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-480766-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.090286 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved