Home > Software engineering >  Vb FTP how to realize BIN download files
Vb FTP how to realize BIN download files

Time:09-23

Now after writing the code in the download, run into some of the server to download file will be garbled, checked the, use the command line to bin download, will not change the original code, not cause this kind of phenomenon, I imagine in the CMD command, after the connection is successful, the next command bin. Into this binmary mode, are there in this API,
I used to use is this a few achieve download, here can improve my above functions?
InternetOpen
InternetConnect
FtpGetFile



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

InternetOpen (" vb wininet ", 1, vbNullString, vbNullString, 0)
InternetConnect (mFTPOpen mAddress, mPoint, mUser mPassWord, 1, 0, 0) connection
FtpGetFile (mFTPConn RomeFileName, LocalPath, False, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY Or INTERNET_FLAG_RELOAD, 0) to download

CodePudding user response:

Did not understand, help top, vb is almost forgotten

CodePudding user response:

Fyi:
 VERSION 5.00 
Object="{48 e59290 cf - 9880-11-9754-00 aa00c00908} # 1.0 # 0"; "MSINET. OCX"
The 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 'Windows default
The Begin VB.Com mandButton Command1
Caption="download"
Height=495
Left=1440
TabIndex=0
Top=1320
Width=1215
End
The Begin InetCtlsObjects. Inet rc.inet1
Left=15
Top=15
_ExtentX=1005
_ExtentY=1005
_Version=393216
End
End
The Attribute VB_Name="Form1"
The Attribute VB_GlobalNameSpace=False
The Attribute VB_Creatable=False
The Attribute VB_PredeclaredId=True
The Attribute VB_Exposed=False
Option Explicit
Dim ExeStr As String
Dim the Done As Boolean
Private Sub CMD (CMDSTR As String)
Do
If rc.inet1. StillExecuting=False Then Exit the Do
Loop
ExeStr=CMDSTR
The Done=False
The Debug. Print ExeStr; "="
Rc.inet1. Execute ExeStr
Do
DoEvents
If Done Then Exit the Do
Loop
End Sub
Public Sub ReadNewFile (the File As a String)
Rc.inet1. URL="ftp://123.123.123.123"
Rc.inet1. UserName="UserName"
Rc.inet1. Password="Password"

'CMD "PWD"
'CMD "CD../files
"'CMD "DIR"
'CMD "GET" + + App File. The Path + "" + File

CMD "GET.. The File/files/" + + 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 an Integer)
Dim intFile As Integer
Dim vtData () As Byte
Dim STR As String
'On Error GoTo ISCerr
The Debug. Print "State="; The State,
Select the Case State
Case 0
The Debug. Print "icNone
"Case 1
The Debug. Print "icHostResolvingHost
"Case 2
The Debug. Print "icHostResolved
"Case 3
The Debug. Print "icConnecting
"Case 4
The Debug. Print "icConnected
"Case 5
The Debug. Print "icRequesting
"Case 6
The Debug. Print "icRequestSent
"Case 7
The Debug. Print "icReceivingResponse
"Case 8
The Debug. Print "icResponseReceived
"If Left (ExeStr, 2)="CD" Then Done=True
Case 9
The Debug. Print "icDisconnecting
"Case 10
The Debug. Print "icDisconnected
"The Done=True
Case 11
The Debug. Print "icError of []" + ExeStr + "="; Rc.inet1. ResponseInfo
The Done=True
Case 12
The Debug. Print "icResponseCompleted -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -"
Do
STR=rc.inet1. GetChunk (1024, icString)
If LenB (STR)=0, Then Exit the Do
The Debug. Print STR
Loop
The Done=True
End the Select
The Exit Sub
ISCerr:
Resume Next
End Sub
  •  Tags:  
  • API
  • Related