Public Sub DownloadFile(ByVal sFileName As String)
DownloadFile(sFileName, "", False)
End Sub
' Download a remote file to the local folder of the assembly, and keep the same file name.
Public Sub DownloadFile(ByVal sFileName As String, _
ByVal bResume As Boolean)
DownloadFile(sFileName, "", bResume)
End Sub
'Download a remote file to a local file name. You must include a path.
'The local file name will be created or will be overwritten, but the path must exist.
Public Sub DownloadFile(ByVal sFileName As String, _
ByVal sLocalFileName As String)
DownloadFile(sFileName, sLocalFileName, False)
End Sub
' Download a remote file to a local file name and include a path. Then, set the
' resume flag. The local file name will be created or will be overwritten, but the path must exist.
Public Sub DownloadFile(ByVal sFileName As String, _
ByVal sLocalFileName As String, _
ByVal bResume As Boolean)
Dim st As Stream
Dim output As FileStream
Dim cSocket As Socket
Dim offset, npos As Long
If (Not (m_bLoggedIn)) Then
Login()
End If
SetBinaryMode(True)
If (sLocalFileName.Equals("")) Then
sLocalFileName = sFileName
End If
If (Not (File.Exists(sLocalFileName))) Then
st = File.Create(sLocalFileName)
st.Close()
End If
output = New FileStream(sLocalFileName, FileMode.Open)
cSocket = CreateDataSocket()
offset = 0
If (bResume) Then
offset = output.Length
If (offset > 0) Then
'Send an FTP command to restart.
SendCommand("REST " & offset)
If (m_iRetValue <> 350) Then
offset = 0
End If
End If
If (offset > 0) Then
npos = output.Seek(offset, SeekOrigin.Begin)
End If
End If
'Send an FTP command to retrieve a file.
SendCommand("RETR " & sFileName)
If (Not (m_iRetValue = 150 Or m_iRetValue = 125)) Then
output.Close()
MessageString = m_sReply
Throw New IOException(m_sReply.Substring(4))
End If
Do While (True)
m_aBuffer.Clear(m_aBuffer, 0, m_aBuffer.Length)
m_iBytes = cSocket.Receive(m_aBuffer, m_aBuffer.Length, 0)
output.Write(m_aBuffer, 0, m_iBytes)
If (m_iBytes <= 0) Then
Exit Do
End If
Loop
output.Close()
If (cSocket.Connected) Then
cSocket.Close()
End If
ReadReply()
If (Not (m_iRetValue = 226 Or m_iRetValue = 250)) Then
MessageString = m_sReply
Throw New IOException(m_sReply.Substring(4))
End If
End Sub
#End Region
#Region "FTP文件上传"
' This is a function that is used to upload a file from your local hard disk to your FTP site.
Public Sub UploadFile(ByVal sFileName As String)
UploadFile(sFileName, False)
End Sub
' This is a function that is used to upload a file from your local hard disk to your FTP site
' and then set the resume flag.
Public Sub UploadFile(ByVal sFileName As String, _
ByVal bResume As Boolean)
Dim cSocket As Socket
Dim offset As Long
Dim input As FileStream
Dim bFileNotFound As Boolean
If (Not (m_bLoggedIn)) Then
Login()
End If
cSocket = CreateDataSocket()
offset = 0
Try
If (bResume) Then
Try
SetBinaryMode(True)
offset = GetFileSize(sFileName)
Catch ex As Exception
offset = 0
End Try
End If
If (offset > 0) Then
SendCommand("REST " & offset)
If (m_iRetValue <> 350) Then
'The remote server may not support resuming.
offset = 0
End If
End If
'Send an FTP command to store a file.
SendCommand("STOR " & Path.GetFileName(sFileName))
If (Not (m_iRetValue = 125 Or m_iRetValue = 150)) Then
MessageString = m_sReply
Throw New IOEx