vb FTP 怎么实现BIN 模式下载文件呀

syf255 2015-12-08 08:47:36
现写的代码在下载完之后,碰到有些服务器下载来的文件会是乱码,查了一下,用命令行bin模式下载,不会改变其原来编码,不会造成这种现象。 我想象CMD命令里那样,连接成功之后,下个命令bin.就转换成这个binmary模式了,这个api里有没有这样的。
我原来用的是这几个实现下载的。这里可以改进实现我上述的功能吗?
internetOpen
InternetConnect
FtpGetFile



Private Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
Private Const FTP_TRANSFER_TYPE_ASCII = &H1
Private Const FTP_TRANSFER_TYPE_BINARY = &H2
Private Const INTERNET_FLAG_RELOAD = &H80000000
Private Const FILE_ATTRIBUTE_NORMAL = &H80

InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0)
InternetConnect(mFTPOpen, mAddress, mPoint, mUser, mPassWord, 1, 0, 0) 连接
FtpGetFile(mFTPConn, RomeFileName, LocalPath, False, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY Or INTERNET_FLAG_RELOAD, 0) 下载
...全文
18687 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-11-15
  • 打赏
  • 举报
回复
仅供参考:
VERSION 5.00
Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
Begin VB.Form Form1
   BorderStyle     =   1  'Fixed Single
   ClientHeight    =   3060
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4035
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3060
   ScaleWidth      =   4035
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1
      Caption         =   "下载"
      Height          =   495
      Left            =   1440
      TabIndex        =   0
      Top             =   1320
      Width           =   1215
   End
   Begin InetCtlsObjects.Inet Inet1
      Left            =   -15
      Top             =   -15
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim ExeStr As String
Dim Done As Boolean
Private Sub cmd(cmdstr As String)
    Do
        If Inet1.StillExecuting = False Then Exit Do
    Loop
    ExeStr = cmdstr
    Done = False
    Debug.Print ExeStr; "="
    Inet1.Execute , ExeStr
    Do
        DoEvents
        If Done Then Exit Do
    Loop
End Sub
Public Sub ReadNewFile(File As String)
    Inet1.URL = "ftp://123.123.123.123"
    Inet1.UserName = "username"
    Inet1.Password = "password"

    'cmd "PWD"
    'cmd "CD ../files"
    'cmd "DIR"
    'cmd "GET " + File + App.Path + "\" + File

    cmd "GET ../files/" + File + App.Path + "\" + File

    cmd "QUIT"
End Sub

Private Sub Command1_Click()
    Command1.Enabled = False
    ReadNewFile ("aFile.ext")
    Command1.Enabled = True
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim intFile As Integer
Dim vtData() As Byte
Dim str As String
'On Error GoTo ISCerr
    Debug.Print "State="; State,
    Select Case State
    Case 0
        Debug.Print "icNone"
    Case 1
        Debug.Print "icHostResolvingHost"
    Case 2
        Debug.Print "icHostResolved"
    Case 3
        Debug.Print "icConnecting"
    Case 4
        Debug.Print "icConnected"
    Case 5
        Debug.Print "icRequesting"
    Case 6
        Debug.Print "icRequestSent"
    Case 7
        Debug.Print "icReceivingResponse"
    Case 8
        Debug.Print "icResponseReceived"
        If Left(ExeStr, 2) = "CD" Then Done = True
    Case 9
        Debug.Print "icDisconnecting"
    Case 10
        Debug.Print "icDisconnected"
        Done = True
    Case 11
        Debug.Print "icError of [" + ExeStr + "]="; Inet1.ResponseInfo
        Done = True
    Case 12
        Debug.Print "icResponseCompleted----------------"
        Do
            str = Inet1.GetChunk(1024, icString)
            If LenB(str) = 0 Then Exit Do
            Debug.Print str
        Loop
        Done = True
    End Select
    Exit Sub
ISCerr:
    Resume Next
End Sub
zhchyun2008 2016-11-15
  • 打赏
  • 举报
回复
没有看懂,帮顶。vb都快忘光了
H Y D R A (c) 2001-2012 by van Hauser / THC http://www.thc.org co-maintained by David (dot) Maciejak @ gmail (dot) com BFG code by Jan Dlabal Licensed under GPLv3 (see LICENSE file) INTRODUCTION ------------ Number one of the biggest security holes are passwords, as every password security study shows. This tool is a proof of concept code, to give researchers and security consultants the possiblity to show how easy it would be to gain unauthorized access from remote to a system. THIS TOOL IS FOR LEGAL PURPOSES ONLY! There are already several login hacker tools available, however none does either support more than one protocol to attack or support parallized connects. It was tested to compile cleanly on Linux, Windows/Cygwin, Solaris, FreeBSD and OSX. Currently this tool supports: AFP, Cisco AAA, Cisco auth, Cisco enable, CVS, Firebird, FTP, HTTP-FORM-GET, HTTP-FORM-POST, HTTP-GET, HTTP-HEAD, HTTP-PROXY, HTTPS-FORM-GET, HTTPS-FORM-POST, HTTPS-GET, HTTPS-HEAD, HTTP-Proxy, ICQ, IMAP, IRC, LDAP, MS-SQL, MYSQL, NCP, NNTP, Oracle Listener, Oracle SID, Oracle, PC-Anywhere, PCNFS, POP3, POSTGRES, RDP, Rexec, Rlogin, Rsh, SAP/R3, SIP, SMB, SMTP, SMTP Enum, SNMP, SOCKS5, SSH (v1 and v2), Subversion, Teamspeak (TS2), Telnet, VMware-Auth, VNC and XMPP. However the module engine for new services is very easy so it won't take a long time until even more services are supported. Your help in writing, enhancing or fixing modules is highly appreciated!! :-) HOW TO COMPILE -------------- For hydra, just type: ./configure make make install If you need ssh module support, you have to setup libssh on your system, get it from http://www.libssh.org, for ssh v1 support you also need to add "-DWITH_SSH1=On" option in the cmake command line. If you use Ubuntu, this will install supplementary libraries needed for a few optional modules: apt-get install

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧