FTP传档问题
FtpConnection 站上有人贴过我就不重贴了~问问FtpConnection这段代码怎改成可传送二进位资料封包的写法?
FtpConnection原档的类模块CFtpConnection中的一小段~
程序代码:
Private Sub UploadData(lStartPoint As Long)
'--------------------------------------------------------------------------------
'Author :Oleg Gdalevich
'Date/Time :14.09.99
'Purpose :Opens file, reads data from the file and
' sends the data to remote computer by 4kb (CHANK_SIZE) chanks.
'Description :If file size is more than CHANK_SIZE the procedure called one or
' multiple times from wscFtpData_SendComplete event procedure.
'--------------------------------------------------------------------------------
Const CHANK_SIZE As Integer = 4096
Static bFileIsOpen As Boolean 'flag variable
Static lChanksCount As Long 'quantity of chanks to send
Static lCounter As Long 'sent chanks counter
Static intRemainder As Integer '
Dim strData As String 'data buffer to send
On Error GoTo UploadData_Err_Handler
'if bFileIsOpen = True, the procedure was called before
If m_bFileIsOpened Then
'if we have to send next chank
If lCounter < lChanksCount And lCounter > 0 Then
'prepare the buffer
strData = Space(CHANK_SIZE)
'increament counter
lCounter = lCounter + 1
'read data from file
Get m_intLocalFileID, , strData
'send data
wscData.SendData strData
Else
'all the data is sent
If lCounter = 0 Then
'
'close data connection to inform ftp server
'that transfer is comlteted
'
wscData.Close
'
'close local file
'
Close #m_intLocalFileID
'
RaiseEvent StateChanged(FTP_TRANSFER_COMLETED)
'
'reset values of all static and module
'level variables
'
m_lUploadedBytes = 0: lChanksCount = 0: intRemainder = 0
m_bFileIsOpened = False: m_bUploadFile = False
'
Else
'all the chanks are sent
'now we have to send the remainder
'
'prepare the buffer
strData = Space(intRemainder)
'reset the counter
lCounter = 0
'read data from file
Get m_intLocalFileID, , strData
'send data
m_objTimeOut.StartTimer
Do
DoEvents
'
If m_objTimeOut.Timeout Then
m_LastError = ERROR_FTP_USER_TIMEOUT
Exit Do
End If
'
If wscData.State = sckConnected Then
wscData.SendData strData
Exit Do
End If
Loop
m_objTimeOut.StopTimer
End If
End If
Else
'
'if we are here, the procedure called at first time
'
m_bFileIsOpened = True 'turn on flag variable
'
m_intLocalFileID = FreeFile
'
Open m_strLocalFilePath For Binary As m_intLocalFileID
'
If lStartPoint > 0 Then
Seek m_intLocalFileID, lStartPoint + 1
m_lUploadedBytes = lStartPoint
'get quantity of chancks to send
lChanksCount = CLng((FileLen(m_strLocalFilePath) - lStartPoint) \ CHANK_SIZE)
'get remainder in bytes
intRemainder = (FileLen(m_strLocalFilePath) - lStartPoint) Mod CHANK_SIZE
Else
'
'get quantity of chancks to send
lChanksCount = CLng(FileLen(m_strLocalFilePath) \ CHANK_SIZE)
'
'get remainder in bytes
intRemainder = FileLen(m_strLocalFilePath) Mod CHANK_SIZE
End If
If lChanksCount = 0 Then
'if amount of data is less then 4Kb
'prepare buffer to read data from a file
strData = Space(intRemainder)
Else
'
'prepare buffer to read data from a file
strData = Space(CHANK_SIZE)
'increament counter of sent chanks
lCounter = 1
End If
'open file to read data
'Open m_strLocalFilePath For Binary As #intFile
'read data to buffer strData
Get m_intLocalFileID, , strData
'send data
Do
DoEvents
If wscData.State = sckConnected Then
wscData.SendData strData
Exit Do
End If
Loop
'
'If lCounter>0, file size if equal or less then chank size
'and we have to send more data. At the next time this sub will
'be called from wscData_SendComplete event procedure to send
'next chank or remainder.
'
End If
Exit Sub
Exit_Label:
Exit Sub
UploadData_Err_Handler:
If Not ProcessWinsockError(Err.Number, Err.Description) Then
Err.Raise vbObjectError + 1000 + Err.Number, "CFtpConnection.UploadData", Err.Description
End If
' Close #intFile
GoTo Exit_Label
End Sub
这程序有二进位传档的功能~但是只是摆好看的~实际上传二步进位档~资料都会被改写只有传的ASCII档会正常~查了好久~怀疑是这段Else
之后惹出的问题~二进位资料格式应该是字节型态吧?用String声明怪不得只会跑ASCII模式~征高手指点要怎改这后半段?
另外它有Open #没有 Close #~这也要向高手讨教一下~这也行吗?(运行上居然不会有问题)
和怎样声明 Byte * 4 的宽度?







