當前位置:首頁 » 文件傳輸 » vbftp上傳下載
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

vbftp上傳下載

發布時間: 2022-10-04 09:30:30

① 我寫的vb的ftp上傳與下載的代碼哪裡出問題了正確的上傳與下載的代碼包含那些

要實現在這個代碼太多,在這里發有點不太現實,VB 實現 FTP 用 WinSock 控制項或API。做該類程序主要是握手控制,即返回值的處理並做相應傳輸,另外就是了解每個 FTP 命令的作用,這樣做個 FTP 服務端或客戶端都不是什麼難事。參考書籍:《Visual Basic網路通信協議分析與應用實現》,該書詳細講解多種 VB 的 FTP 實現與高級開發。篇幅很大

② VB6.0 FTP下載上傳問題【可加分!】

要用到Microsoft Internet Transfer Control 6.0控制項:

Private Sub Command1_Click()
Inet1.Execute "ftp://123:[email protected]", "get 123.exe d:\123.exe" '下載123.exe文件到d:\
End Sub

Private Sub Command2_Click()
Inet1.Execute "ftp://123:[email protected]", "put d:\123.exe 123.exe" '上傳d:\123.exe到伺服器
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
If State = 12 Then Inet1.Execute , "close" '如果下載或上傳完畢則關閉FTP連接
End Sub

其中要用到的URL格式為:
ftp://用戶名:密碼@域名或IP地址:埠號
FTP命令格式:
下載: get 伺服器目錄名/.../文件名 本地文件名
上傳: put 本地文件名 伺服器目錄名/.../文件名

③ VB FTP 上傳和下載問題

用vb實現ftp的上傳下載

Option Explicit

Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
(ByVal sAgent As String, ByVal LAccessType As Long, ByVal sProxyName As String, _
ByVal SProxyBypass As String, ByVal lFlags As Long) As Long

Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _
(ByVal hInternetSession As Long, ByVal sServerName As String, _
ByVal nServerPort As Integer, ByVal sUsername As String, _
ByVal sPassword As String, ByVal lService As Long, _
ByVal lFlags As Long, ByVal lContext As Long) As Long

Public Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" _
(ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean

Public Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" _
(ByVal hFtpSession As Long, ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean

Public Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" _
(ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean

Public Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" _
(ByVal hFtpSession As Long, ByVal lpszExsiting As String, ByVal lpszNew As String) As Boolean

Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

Public Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" _
(ByVal hFtpSession As Long, ByVal lpszSearchFile As String, _
lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, _
ByVal dwContent As Long) As Long

Public Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" _
(ByVal hFind As Long, lpvFndData As WIN32_FIND_DATA) As Long

Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Type WIN32_FIND_DATA
dwFilAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * 260
cAlternate As String * 14
End Type

Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Sub Command1_Click()
lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, vbNullString, 0&)
If lnginet Then
lnginetconn = InternetConnect(lnginet, "ip地址", 0, _
"用戶名", "密碼", 1, 0, 0)
If lnginetconn Then
blnRC = FtpGetFile(lnginetconn, "website/address.asp", "c:\address.asp", 0, 0, 1, 0)
If blnRC Then
MsgBox "download ok!!!"
End If
InternetCloseHandle lnginetconn
InternetCloseHandle lnginet
MsgBox "close ok!!!"
Else
MsgBox "can't connect"
End If
Else
MsgBox "ftp wrong"
End If
End Sub

Private Sub Command2_Click()
Dim pData As WIN32_FIND_DATA
Dim lngHINet As Long
Dim intError As Integer
Dim strTemp As String
Dim blnRC As Boolean
pData.cFileName = String(260, 0)
lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, vbNullString, 0&)
If lnginet Then
lnginetconn = InternetConnect(lnginet, "IP地址", 0, _
"用戶名", "密碼", 1, 0, 0)
If lnginetconn Then
lngHINet = FtpFindFirstFile(lnginetconn, "*.*", pData, 0, 0)
strTemp = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
Do
pData.cFileName = String(260, 0)
blnRC = InternetFindNextFile(lngHINet, pData)
If Not blnRC Then
Exit Do
Else
strTemp = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
End If

Loop
Text1.Text = strTemp
End If
End If
InternetCloseHandle lngHINet

InternetCloseHandle lnginetconn
InternetCloseHandle lnginet

End Sub

④ VB6.0 FTP下載上傳問題【可加分!】

首先介紹ftp下載,代碼如下: Const Str_FtpServer As String = " ftp://ftp.lob.cn" Private Str_Username As String = "lob" Private Str_Password As String = "xxxxxxxx" Private Sub DownloadFile(ByVal Str_Path As String) Try Dim Str_Filename As String = Str_Path Dim ftpReq As FtpWebRequest = WebRequest.Create(Str_Filename) ftpReq.Method = WebRequestMethods.Ftp.DownloadFile ftpReq.Credentials = New NetworkCredential(Str_Username, Str_Password) Dim FTPResp As FtpWebResponse = ftpReq.GetResponse Dim ftpRespStream As Stream = FTPResp.GetResponseStream 'FTPResp.StatusDescription 為回顯狀態的描述 可用於調試 ftpRespStream.Save("d:\lobdotcn.rar") '保存到本地的路徑,如果你樂意也可以直接定義到參數中 FTPResp.Close() Catch ex As Exception MsgBox(ex.Message) End Try End Sub 調用方式:DownloadImage(Str_FtpServer& "/logo.jpg")==============================================================你先看看是你想要的不?是的話再往下看從這里過來的: http://blog.chinaunix.net/u/22170/showart_475726.html 呵呵我是做C#的,但是看你這分數實在太誘人,就幫你找了找~

記得採納啊

⑤ 用VB製作一個FTP上傳下載的工具

一個FTP,一個Command、三個Text Private Sub Command1_Click() On Error VB寫的FTP上傳下載工具》。有需要幫助也可以在我的網站里留言說明: . 留言

⑥ VB的FTP上傳下載操作函數

直接用自帶的ftp命令 也是一樣的

無論是FTP,還是HTTP,都可以下載,如果是FTP,如果要登錄請在路徑中指定用戶名和密碼,如下載地址是www.abc.com/abc.rar" target="_blank">ftp://www.abc.com/abc.rar,用戶名是software,密碼是software,則在下載地址就輸入:www.abc.com/abc.rar " target="_blank">ftp://software:[email protected]/abc.rar

用shell 好用的很 自己搞函數 還不穩定

⑦ vb編寫ftp 能上傳下載文件

1、利用Inet控制項上傳文件

格式:inet1.execute , "put 本地文件 遠程文件"

範例:

'初始化Inet控制項
Inet1.Protocol = icFTP
Inet1.URL = "ftp://u0501901.k1.13939.org"
Inet1.RemotePort = 21
Inet1.UserName = "u0501901"
Inet1.Password = "750531179574"

Label3.Caption = "正在上傳....."

'先關閉當前的資料庫存連接
cn.Close

Inet1.Execute , "put" & " " & App.Path & "\vbhelp.mdb" & " " & "/vbhelp/vbhelp.mdb"

Do While Inet1.StillExecuting
DoEvents
Loop
Label3.Caption = "上傳成功"

'重新連接資料庫
dbconnect

2、利用Inet控制項下載文件

格式: inet1.execute , "get 遠程文件 本地文件",注意空格

'初始化INET1控制項
Inet1.Protocol = icFTP
Inet1.URL = "ftp://u0501901.k1.13939.org"
Inet1.RemotePort = 21
Inet1.UserName = "u0501901"
Inet1.Password = "750531179574"

Label3.Caption = "正在下載...."

'格式: inet1.execute , "get 遠程文件 本地文件",注意空格
Inet1.Cancel
Inet1.Execute , "GET /vbhelp/vbhelp.mdb c:\temp\vbhelp.mdb"
Do While Inet1.StillExecuting
DoEvents
Loop

label3.caption="下載成功"

3、利用INET控制項建立遠程的文件夾

Inet1.AccessType = icUseDefault
Inet1.RemotePort = 21
Inet1.Protocol = icFTP
Inet1.URL = "u0711084.k1.13939.org"
Inet1.UserName = "u0711084"
Inet1.Password = "750531179574"

Inet1.Execute , "mkdir vbtest"
Do While Inet1.StillExecuting
DoEvents
Loop

Inet1.Execute , "close"
Inet1.Execute , "quit"
MsgBox "成功建立文件夾"

4、利用INET控制項刪除遠程文件夾

方法跟建立文件夾一樣,刪除命令為rmdir,但只能刪除空目錄,刪除文件用delete

⑧ 怎樣在VB中用winsock實現ftp的上傳下載

Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Info() As String, TimerCountA As Long

Private WithEvents wscControl As MSWinsockLib.Winsock
Private WithEvents wscData As MSWinsockLib.Winsock
Private Tmp As String, FileSize As String, DFile As String

Private Sub TimerControl_Timer()
LabelControl.Caption = "控制連接狀態:" & WinSState(wscControl.State)
End Sub

Private Sub TimerData_Timer()
LabelData.Caption = "數據連接狀態:" & WinSState(wscData.State)
End Sub

Private Sub wscControl_DataArrival(ByVal bytesTotal As Long)
Dim i As String
wscControl.GetData Tmp
End Sub

Private Sub wscData_DataArrival(ByVal bytesTotal As Long)
Dim ByteData() As Byte
wscData.GetData ByteData(), vbByte
Open DFile For Binary Lock Write As #1
ProgressBar.Value = FileLen(DFile)
If LOF(1) > 0 Then
Seek #1, LOF(1) + 1
End If
Put #1, , ByteData()
Close #1
End Sub

Private Sub wscData_Close()
wscData.Close
End Sub

Function ChkTime()
Dim i As Integer
i = 50
Do While i > 0
If Tmp <> "" Then Exit Function
Sleep (100)
DoEvents
i = i - 1
Loop
wscControl.Close
ChkTime = True
End Function

Function ConnFtp(HostIp, HostPort, User, Pass)
If wscControl Is Nothing Then
Set wscControl = Controls.Add("MSWinsock.Winsock", "wscControl", Me)
TimerControl.Interval = 100
TimerControl.Enabled = True
End If
With wscControl
.RemoteHost = HostIp
.RemotePort = HostPort
.Connect
End With
If ChkTime Then
ConnFtp = "連接超時,是否重試?"
Exit Function
End If
Debug.Print Tmp
Select Case Left(Tmp, 3)
Case "220"
Tmp = ""
wscControl.SendData "USER " & User & vbCrLf
Debug.Print "USER " & User & vbCrLf
If ChkTime Then
ConnFtp = "連接錯誤USER,是否重試?" & vbCrLf & Tmp
Exit Function
End If
Debug.Print Tmp
Select Case Left(Tmp, 3)
Case "331"
Tmp = ""
wscControl.SendData "PASS " & Pass & vbCrLf
Debug.Print "PASS " & Pass & vbCrLf
PassCS:
If ChkTime Then
ConnFtp = "連接錯誤PASS,是否重試?" & vbCrLf & Tmp
Exit Function
End If
Debug.Print Tmp
Select Case Left(Tmp, 3)
Case "230"
If InStr(Tmp, "230 ") > 0 Then
ConnFtp = "OK"
Tmp = ""
Exit Function
End If
Tmp = ""
GoTo PassCS
Case "530"
ConnFtp = "登陸失敗,用戶名或密碼錯誤,是否重試?" & vbCrLf & Tmp
wscControl.Close
Tmp = ""
Exit Function
End Select
End Select
End Select
ConnFtp = "錯誤"
End Function

Function DownFile(File As String, TransferMode As String)
Dim FileHaveLen As String
If wscControl.State <> 7 Then
MsgBox "請確認當前連接狀態!1"
Exit Function
End If
wscControl.SendData "NOOP " & vbCrLf
Debug.Print "NOOP " & vbCrLf
If ChkTime Or Left(Tmp, 3) <> 200 Then
Debug.Print Tmp
DownFile = "請確認當前連接狀態!2" & vbCrLf & Tmp
Tmp = ""
Exit Function
Else
Debug.Print Tmp
Tmp = ""
End If
If TransferMode = "I" Or TransferMode = "A" Then
wscControl.SendData "TYPE " & TransferMode & vbCrLf
Debug.Print "TYPE " & TransferMode & vbCrLf
If ChkTime Or Left(Tmp, 3) <> 200 Then
Debug.Print Tmp
DownFile = "改變狀態失敗!" & vbCrLf & Tmp
Tmp = ""
Exit Function
Else
Debug.Print Tmp
Tmp = ""
End If
End If
File = Replace(File, "\", "/")
Dim PathT As String
PathT = Left(File, InStrRev(File, "/"))
If PathT <> "" Then
wscControl.SendData "CWD " & PathT & vbCrLf
Debug.Print "CWD " & PathT & vbCrLf
If ChkTime Or Left(Tmp, 3) <> 250 Then
Debug.Print Tmp
DownFile = "改變目錄失敗!" & vbCrLf & Tmp
Tmp = ""
Exit Function
Else
Debug.Print Tmp
Tmp = ""
End If
End If
Dim FileT As String
FileT = Right(File, Len(File) - InStrRev(File, "/"))
wscControl.SendData "SIZE " & FileT & vbCrLf
Debug.Print "SIZE " & FileT & vbCrLf
If ChkTime Or Left(Tmp, 3) <> 213 Then
Debug.Print Tmp
DownFile = "取得文件大小失敗!" & vbCrLf & Tmp
Tmp = ""
Exit Function
Else
Debug.Print Tmp
FileSize = Right(Tmp, Len(Tmp) - 4)
ProgressBar.Max = FileSize
Print "文件大小:" + CStr(FormatNumber(FileSize / 1024, 2)) + "KB..."
Tmp = ""
End If
wscControl.SendData "PASV" & vbCrLf
Debug.Print "PASV" & vbCrLf
If ChkTime Or Left(Tmp, 3) <> 227 Then
Debug.Print Tmp
DownFile = "獲取Pasv埠失敗!" & vbCrLf & Tmp
Tmp = ""
Exit Function
Else
Debug.Print Tmp
Dim Tmp1, Tmp2, Tmp3, Tmp4, TmpIp, TmpPort
Tmp1 = InStr(Tmp, Chr(40)) + 1
Tmp2 = InStrRev(Tmp, Chr(41))
Tmp3 = Mid(Tmp, Tmp1, Tmp2 - Tmp1)
Tmp4 = Split(Tmp3, ",")
TmpIp = Tmp4(0) & "." & Tmp4(1) & "." & Tmp4(2) & "." & Tmp4(3)
TmpPort = Tmp4(4) * 256 + Tmp4(5)
Tmp = ""
End If
Open DFile For Binary Lock Write As #1
If LOF(1) > 0 Then
FileHaveLen = FileLen(DFile)
Close #1
If MsgBox("文件已存在,是否續傳?", vbYesNo, "提示:") <> vbYes Then
Kill DFile
Else
wscControl.SendData "REST " & FileHaveLen & vbCrLf
Debug.Print "REST " & FileHaveLen & vbCrLf
If ChkTime Or Left(Tmp, 3) <> 350 Then
MsgBox "伺服器不支持續傳,將重新下載文件!" & vbCrLf & Tmp
Kill DFile
End If
Debug.Print Tmp
Tmp = ""
End If
Else
Close #1
End If
'數據下載部分
If wscData Is Nothing Then
Set wscData = Controls.Add("MSWinsock.Winsock", "wscData", Me)
TimerData.Interval = 100
TimerData.Enabled = True
End If
With wscData
.RemoteHost = TmpIp
.RemotePort = TmpPort
.Connect
End With
wscControl.SendData "RETR " & FileT & vbCrLf
Debug.Print "RETR " & FileT & vbCrLf
If ChkTime Then
DownFile = "連接數據超時!"
Exit Function
End If
Debug.Print Tmp
If InStr(Tmp, "226 ") > 0 Then GoTo End1
Tmp = ""
Do While wscData.State = 7
DoEvents
Loop
If ChkTime Then
DownFile = "下載失敗!"
Exit Function
End If
Debug.Print Tmp
End1:
Tmp = ""
DownFile = "OK"
End Function

Private Sub Command2_Click()
Dim n
DFile = "C:\Documents and Settings\Administrator\桌面\a.rar"
a1:
n = ConnFtp("127.0.0.1", "21", "temp", "tmp")
If n <> "OK" Then
If MsgBox(n, vbYesNo, "提示:") = vbYes Then GoTo a1
Exit Sub
End If
n = DownFile("system\a.rar", "I")
If n <> "OK" Then
MsgBox n, , "提示:"
Exit Sub
End If
MsgBox "下載成功!"
End Sub

'時間有限只能給你寫這些了!以後有機會的話再給你貼吧!我QQ155209220

⑨ 急!用VB代碼實現FTP的上傳和下載(高分)

要實現在這個代碼太多,在這里發有點不太現實,VB 實現 FTP 用 WinSock 控制項或API。
做該類程序主要是握手控制,即返回值的處理並做相應傳輸,另外就是了解每個 FTP 命令的作用,這樣做個 FTP 服務端或客戶端都不是什麼難事。

⑩ vb如何實現FTP下載

Call Inet1.Execute(,"put 本地地址\文件名 ftp地址\文件名")『上傳ftp文件代碼
Call Inet1.Execute(,"get ftp地址\文件名 本地地址\文件名")』下載ftp文件代碼
你要在inet1的自定義中設置好