1. VB操作FTP問題
Inet6.Cancel
和
Inet6.Execute , "CLOSE"
Inet6.Execute , "QUIT"
移到循環外面,比如:
Inet6.Cancel
For i = 0 To List1.ListCount - 1
Inet6.Execute , "get MZ/" & List1.List(i) & " D:\NCTEMP" & List1.List(i)
Do While Inet6.StillExecuting
DoEvents
Loop
Next
Inet6.Execute , "CLOSE"
Inet6.Execute , "QUIT"
下面的上傳文件也一樣。
FTP的get命令和put命令是可以連續執行的,無需下載一個文件就退出,然後又再登錄下載下一個文件,這樣不但效率低,而且很可能就是在這個不斷登錄的過程中造成文件下載異常。
限於條件,以上語句我無法測試,你自己試試看對不對。
希望我的回答可以幫助到你,謝謝
2. VB中如何實現上傳文件的功能
用script腳本 直接調用FTP 命令實現上傳文件到FTP伺服器。
代碼如下:
'定義API函數
ConstSYNCHRONIZE=&H100000
ConstINFINITE=&HFFFFFFFF
"kernel32"(ByValdwDesiredAccessAsLong,ByValbInheritHandleAsLong,ByValdwProcessIdAsLong)AsLong
"kernel32"(ByValhObjectAsLong)AsLong
"kernel32"(ByValhHandleAsLong,ByValdwMillisecondsAsLong)AsLong
PrivateSubCommand1_Click()
DimfilenameAsString
DimftpAsString
DimunameAsString
DimupinAsString
ftp=InputBox("請輸入伺服器地址")
uname=InputBox("請輸入帳號",,"anonymous")
upin=InputBox("請輸入密碼",,"IE@User")
filename=Timer()'取時間為文件名filename
Openfilename&".script"ForOutputAs#1'生成filename.script腳本,傳輸FTP用
Print#1,"user"
Print#1,uname
Print#1,upin
Print#1,"pwd"
Print#1,"hash"
Print#1,"put"&filename&".txt"
Print#1,"quit"
Close#1
Openfilename&".txt"ForOutputAs#1'生成的filename.txt保存了combo1和text1的文字
Print#1,Text1.Text
Print#1,Combo1.Text
Close#1
DoEvents
'調用ftp命令傳輸,不需要inet或winsock控制項
DimpIdAsLong,pHndAsLong
pId=Shell("ftp-n-s:"&filename&".script"&""&ftp,vbHide)
pHnd=OpenProcess(SYNCHRONIZE,0,pId)
IfpHnd<>0Then
CallWaitForSingleObject(pHnd,INFINITE)
CallCloseHandle(pHnd)
EndIf
Killfilename&".script"'因為script腳本保存了帳號和密碼,當傳輸完成後刪除filename.script腳本
EndSub
3. vb6.0調用cmd上傳文件到ftp伺服器,急!
外部調用ftp 指令不用手動輸入命令是不可能的,因為ftp指令沒有提供過多的命令行參數,可以這樣
創建Internet Transfer 控制項
inter.execute ftpAddress,"send " & LocalFilePaht & " " & RemoteName
這樣就能上傳了
當然如果ftp是有密碼的那地址要改一下
就是
ftp://UserName:PassWord@FTPAddress
就是這樣的了
4. vb 命令行 ftp
把你的VB程序拷貝到BAT和TXT文件的目錄下就行了,或者修改你的FTP.BAT,在裡面有FTP.TXT文件的地方加上全路徑名即可。
加入你原來的FTP.BAT有下面一行:
FTP -I FTP.TXT
那麼可以修改為:
FTP -I D:\DATA\FTP.TXT
5. vb如何上傳文件到指定ftp
最簡單的方法是用ftp批處理,代碼如下
open app.path & "\ftpcmd.ftp" for output as #1 '創建一個ftp命令文件
print #1, "open " & "IP" '打開ftp伺服器
print #1, "user " & "用戶名"
print #1, "pass " & "密碼"
print #1, "lcd " & "本地文件路徑" '指定本地文件所在目錄
print #1, "put " & "文件名"
close #1 'frp命令文件寫完了
shell "ftp -n -s:" & app.path & "\ftpcmd.ftp" '調用系統ftp,並執行上面寫的ftpcmd.ftp
6. VB與FTP編程
建議樓主用winsock連接FTP伺服器,發送FTP命令來實現交互,另外說明下,目錄的獲取與文件的傳輸是另開埠進行的,以下是命令表
ftp協議命令字(轉)
命令 描述
ABOR 中斷數據連接程序
ACCT <account> 系統特權帳號
ALLO <bytes> 為伺服器上的文件存儲器分配位元組
APPE <filename> 添加文件到伺服器同名文件
CDUP <dir path> 改變伺服器上的父目錄
CWD <dir path> 改變伺服器上的工作目錄
DELE <filename> 刪除伺服器上的指定文件
HELP <command> 返回指定命令信息
LIST <name> 如果是文件名列出文件信息,如果是目錄則列出文件列表
MODE <mode> 傳輸模式(S=流模式,B=塊模式,C=壓縮模式)
MKD <directory> 在伺服器上建立指定目錄
NLST <directory> 列出指定目錄內容
NOOP 無動作,除了來自伺服器上的承認
PASS <password> 系統登錄密碼
PASV 請求伺服器等待數據連接
PORT <address> IP 地址和兩位元組的埠 ID
PWD 顯示當前工作目錄
QUIT 從 FTP 伺服器上退出登錄
REIN 重新初始化登錄狀態連接
REST <offset> 由特定偏移量重啟文件傳遞
RETR <filename> 從伺服器上找回(復制)文件
RMD <directory> 在伺服器上刪除指定目錄
RNFR <old path> 對舊路徑重命名
RNTO <new path> 對新路徑重命名
SITE <params> 由伺服器提供的站點特殊參數
SMNT <pathname> 掛載指定文件結構
STAT <directory> 在當前程序或目錄上返回信息
STOR <filename> 儲存(復制)文件到伺服器上
STOU <filename> 儲存文件到伺服器名稱上
STRU <type> 數據結構(F=文件,R=記錄,P=頁面)
SYST 返回伺服器使用的操作系統
TYPE <data type> 數據類型(A=ASCII,E=EBCDIC,I=binary)
USER <username>> 系統登錄的用戶名
標准 FTP 信息如下:
響應代碼 解釋說明
110 新文件指示器上的重啟標記
120 伺服器准備就緒的時間(分鍾數)
125 打開數據連接,開始傳輸
150 打開連接
200 成功
202 命令沒有執行
211 系統狀態回復
212 目錄狀態回復
213 文件狀態回復
214 幫助信息回復
215 系統類型回復
220 服務就緒
221 退出網路
225 打開數據連接
226 結束數據連接
227 進入被動模式(IP 地址、ID 埠)
230 登錄網際網路
250 文件行為完成
257 路徑名建立
331 要求密碼
332 要求帳號
350 文件行為暫停
421 服務關閉
425 無法打開數據連接
426 結束連接
450 文件不可用
451 遇到本地錯誤
452 磁碟空間不足
500 無效命令
501 錯誤參數
502 命令沒有執行
503 錯誤指令序列
504 無效命令參數
530 未登錄網路
532 存儲文件需要帳號
550 文件不可用
551 不知道的頁類型
552 超過存儲分配
553 文件名不允許
7. VB.net連接FTP操作
MSDN上的,看看對你有沒有幫助。GOOD LUCK!
Imports System.Net
Imports System.IO
Mole FtpSample
Sub Main(ByVal args() As String)
If args.Length = 0 OrElse args(0).Equals("/?") Then
DisplayUsage()
ElseIf args.Length = 1 Then
Download(args(0))
ElseIf args.Length = 2 Then
If args(0).Equals("/list") Then
List(args(1))
Else
Upload(args(0), args(1))
End If
Else
Console.WriteLine("Unrecognized argument.")
End If
End Sub
Private Sub DisplayUsage()
Console.WriteLine("USAGE:")
Console.WriteLine(" FtpSample [/? | <FTP download URL> | <local file>")
Console.WriteLine(" <FTP upload URL> | /list <FTP list URL>]")
Console.WriteLine()
Console.WriteLine("where")
Console.WriteLine(" FTP download URL URL of a file to download from an FTP server.")
Console.WriteLine(" FTP upload URL Location on a FTP server to upload a file to.")
Console.WriteLine(" FTP list URL Location on a FTP server to list the contents of.")
Console.WriteLine(" local file A local file to upload to an FTP server.")
Console.WriteLine()
Console.WriteLine(" Options:")
Console.WriteLine(" /? Display this help message.")
Console.WriteLine(" /list Specifies the list command.")
Console.WriteLine()
Console.WriteLine("EXAMPLES:")
Console.WriteLine(" Download a file FtpSample ftp://myserver/download.txt")
Console.WriteLine(" Upload a file FtpSample upload.txt ftp://myserver/upload.txt")
End Sub
Private Sub Download(ByVal downloadUrl As String)
Dim responseStream As Stream = Nothing
Dim fileStream As FileStream = Nothing
Dim reader As StreamReader = Nothing
Try
Dim downloadRequest As FtpWebRequest = _
WebRequest.Create(downloadUrl)
Dim downloadResponse As FtpWebResponse = _
downloadRequest.GetResponse()
responseStream = downloadResponse.GetResponseStream()
Dim fileName As String = _
Path.GetFileName(downloadRequest.RequestUri.AbsolutePath)
If fileName.Length = 0 Then
reader = New StreamReader(responseStream)
Console.WriteLine(reader.ReadToEnd())
Else
fileStream = File.Create(fileName)
Dim buffer(1024) As Byte
Dim bytesRead As Integer
While True
bytesRead = responseStream.Read(buffer, 0, buffer.Length)
If bytesRead = 0 Then
Exit While
End If
fileStream.Write(buffer, 0, bytesRead)
End While
End If
Console.WriteLine("Download complete.")
Catch ex As UriFormatException
Console.WriteLine(ex.Message)
Catch ex As WebException
Console.WriteLine(ex.Message)
Catch ex As IOException
Console.WriteLine(ex.Message)
Finally
If reader IsNot Nothing Then
reader.Close()
ElseIf responseStream IsNot Nothing Then
responseStream.Close()
End If
If fileStream IsNot Nothing Then
fileStream.Close()
End If
End Try
End Sub
Private Sub Upload(ByVal fileName As String, ByVal uploadUrl As String)
Dim requestStream As Stream = Nothing
Dim fileStream As FileStream = Nothing
Dim uploadResponse As FtpWebResponse = Nothing
Try
Dim uploadRequest As FtpWebRequest = WebRequest.Create(uploadUrl)
uploadRequest.Method = WebRequestMethods.Ftp.UploadFile
' UploadFile is not supported through an Http proxy
' so we disable the proxy for this request.
uploadRequest.Proxy = Nothing
requestStream = uploadRequest.GetRequestStream()
fileStream = File.Open(fileName, FileMode.Open)
Dim buffer(1024) As Byte
Dim bytesRead As Integer
While True
bytesRead = fileStream.Read(buffer, 0, buffer.Length)
If bytesRead = 0 Then
Exit While
End If
requestStream.Write(buffer, 0, bytesRead)
End While
' The request stream must be closed before getting the response.
requestStream.Close()
uploadResponse = uploadRequest.GetResponse()
Console.WriteLine("Upload complete.")
Catch ex As UriFormatException
Console.WriteLine(ex.Message)
Catch ex As IOException
Console.WriteLine(ex.Message)
Catch ex As WebException
Console.WriteLine(ex.Message)
Finally
If uploadResponse IsNot Nothing Then
uploadResponse.Close()
End If
If fileStream IsNot Nothing Then
fileStream.Close()
End If
If requestStream IsNot Nothing Then
requestStream.Close()
End If
End Try
End Sub
Private Sub List(ByVal listUrl As String)
Dim reader As StreamReader = Nothing
Try
Dim listRequest As FtpWebRequest = WebRequest.Create(listUrl)
listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails
Dim listResponse As FtpWebResponse = listRequest.GetResponse()
reader = New StreamReader(listResponse.GetResponseStream())
Console.WriteLine(reader.ReadToEnd())
Console.WriteLine("List complete.")
Catch ex As UriFormatException
Console.WriteLine(ex.Message)
Catch ex As WebException
Console.WriteLine(ex.Message)
Finally
If reader IsNot Nothing Then
reader.Close()
End If
End Try
End Sub
End Mole
可以通過設置 Credentials 屬性來指定用於連接伺服器的憑據,也可以將它們包含在傳遞給 Create 方法的 URI 的 UserInfo 部分中。
從 FTP 伺服器下載文件時,如果命令成功,所請求的文件的內容即在響應對象的流中。通過調用 GetResponseStream 方法,可以訪問此流。
如果使用 FtpWebRequest 對象向伺服器上載文件,則必須將文件內容寫入請求流,請求流是通過調用 GetRequestStream 方法或其非同步對應方法(BeginGetRequestStream 和 EndGetRequestStream 方法)獲取的。必須寫入流並在發送請求之前關閉該流。
請求是通過調用 GetResponse 方法或其非同步對應方法(BeginGetResponse 和 EndGetResponse 方法)發送到伺服器的。請求的操作完成時,會返回一個 FtpWebResponse 對象。FtpWebResponse 對象提供操作的狀態以及從伺服器下載的所有數據。
8. 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 好用的很 自己搞函數 還不穩定
9. VB編寫個程序上傳文件到FTP
首先,在VB工具欄中添加部件Microsoft Internet Transfer Control 6.0 ,之後工具箱會多一個Inet的控制項。
拖放該控制項到窗體上,設置控制項中的屬性
protocol : 2-icFTP
RemoteHost : 你的FTP服務IP或域名
RemotePort : 你的FTP埠
URL : 你的FTPURL地址
UserName和Password 這兩個就不用說了
'窗體中添加一個文本框(text1)和一個按鈕(Command1)代碼如下:
Private Sub Command1_Click()
Dim isRight As Boolean
Dim filestr As String
filestr = app.path & "\A"
Inet1.Execute "", "PUT " & filestr & " /A"
isRight = Inet1.StillExecuting '獲取當前是否仍然在執行命令
Do While isRight
isRight = Inet1.StillExecuting
DoEvents
Loop
filestr = app.path & "\B"
Inet1.Execute "", "PUT " & filestr & " /B"
isRight = Inet1.StillExecuting '獲取當前是否仍然在執行命令
Do While isRight
isRight = Inet1.StillExecuting
DoEvents
Loop
filestr = app.path & "\C"
Inet1.Execute "", "PUT " & filestr & " /C"
isRight = Inet1.StillExecuting '獲取當前是否仍然在執行命令
Do While isRight
isRight = Inet1.StillExecuting
DoEvents
Loop
filestr = app.path & "\D"
Inet1.Execute "", "PUT " & filestr & " /a/D"
isRight = Inet1.StillExecuting '獲取當前是否仍然在執行命令
Do While isRight
isRight = Inet1.StillExecuting
DoEvents
Loop
End Sub
Private Sub Inet1_StateChanged(ByVal State As Integer)
text1.Text = text1.Text + CStr(State)
Select Case State
Case 11
text1.text ="在與主機通信的過程中發生了錯誤"
Case 12
text1.Text = "上傳完成"
End Select
End Sub