vb+asp.net 实现上传文件到一个ftp服务器!!在线等了,各位高手!

zl_xue 2003-11-27 02:22:11
如题!我想用代码实现将文件上传到一个ftp地址!如何实现,用什么方法!????我到找了好多资料了,可就是没有头绪,有代码最好了〉!!!

小弟先谢了!
...全文
63 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
bugdragon 2003-12-06
  • 打赏
  • 举报
回复
send message to u
dekey1000 2003-11-28
  • 打赏
  • 举报
回复
用STOCK吧。
zl_xue 2003-11-28
  • 打赏
  • 举报
回复
up
zl_xue 2003-11-28
  • 打赏
  • 举报
回复
这只是一个读取连接信息的函数,只是确定连接错误或成功的信息!~!!

再看看
theng1980 2003-11-28
  • 打赏
  • 举报
回复
有点晕!!
是不是ReadData = sData他们的类型不匹配丫,你用属性type看看类型是否相同
zl_xue 2003-11-28
  • 打赏
  • 举报
回复
代码如下


Private Sub ftp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ftp.Click
fileupload.SendFile("192.168.10.100", "test.txt", "username", "pwd", "f:\ftp.txt")
End Sub

--------------------------------------

Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Text.RegularExpressions

Module fileupload
Private bytWriting As [Byte]()
Private bytReading As Byte()

Dim strAddress As String
Dim strFtpIP As String
Dim intPort As Integer


Public Function SendFile(ByVal strFtpIP As String, _
ByVal strSaveAs As String, ByVal strUsername As String, _
ByVal strPassword As String, ByVal strPath As String)

If Left(strPath, 1) = "/" Or Left(strPath, 1) = "\" Then
strPath = strPath.Remove(1, 1)
End If
If Right(strPath, 1) = "/" Or Right(strPath, 1) = "\" Then
strPath = strPath.Remove(strPath.Length, 1)
End If


Dim objTCPCommand As New TcpClient()
Dim objTCPData As New TcpClient()
Dim objTCPCommandStream As NetworkStream
Dim objTCPDataStream As NetworkStream

Try
objTCPCommand.SendTimeout = 1000
objTCPCommand.Connect(strFtpIP, "21")
objTCPCommandStream = objTCPCommand.GetStream
ReadData(objTCPCommand, objTCPCommandStream)

WriteData(objTCPCommandStream, "USER " & strUsername & vbCrLf)
ReadData(objTCPCommand, objTCPCommandStream)
WriteData(objTCPCommandStream, "PASS " & strPassword & vbCrLf)
ReadData(objTCPCommand, objTCPCommandStream)
WriteData(objTCPCommandStream, "PASV" & vbCrLf)

'get address from response
strAddress = AddressRE.Match(ReadData(objTCPCommand, objTCPCommandStream)).ToString
Dim strPort = portRE.Match(strAddress).ToString
Dim strP1 = p1RE.Match(strPort).ToString
Dim strP2 = p2RE.Match(strPort).ToString
intPort = CInt(strP1) * 256 + CInt(strP2)

'make data connection
objTCPData.SendTimeout = 1000
objTCPData.Connect(strFtpIP, intPort)
objTCPDataStream = objTCPData.GetStream

'change directory
Dim b As Boolean = File.Exists(strPath)
If b Then
If strPath <> "" Then

'***这的返回550的错误The filename, directory name, or
'** volume label
WriteData(objTCPCommandStream, "CWD " & strPath & vbCrLf)
End If
End If

'save file
ReadData(objTCPCommand, objTCPCommandStream)
WriteData(objTCPCommandStream, "STOR " & strSaveAs & vbCrLf)
'If blnMask = True Then
'ReadData(objTCPCommand, objTCPCommandStream)
'WriteData(objTCPDataStream, strFrame)
'Else
'WriteData(objTCPDataStream, strNoFrame)
'End If

'close data connection
ReadData(objTCPCommand, objTCPCommandStream)
objTCPDataStream.Close()
objTCPData.Close()

'quit and close control connection
WriteData(objTCPCommandStream, "QUIT" & vbCrLf)
objTCPCommandStream.Close()
objTCPCommand.Close()

Catch Err As Exception
MsgBox(Err.ToString)
End Try
End Function

Private Function ReadData(ByVal TCPClient, ByVal NETStream) As String
Dim sData As String
Do Until sData <> ""
ReDim bytReading(TCPClient.ReceiveBufferSize)
NETStream.Read(bytReading, 0, TCPClient.ReceiveBufferSize)
sData = Trim(System.Text.Encoding.ASCII.GetString(bytReading))
ReadData = sData
Loop
End Function

Private Sub WriteData(ByVal NETStream As Object, ByVal sData As String)
bytWriting = System.Text.Encoding.ASCII.GetBytes(sData)
NETStream.Write(bytWriting, 0, bytWriting.Length)
End Sub

End Module


为什么呢?//////////
zl_xue 2003-11-28
  • 打赏
  • 举报
回复
我用stock了,而且联接成功了

但是,一道传送文件就是 550的错误The filename, directory name, or volume label syntax is incorrect.

送的本地文件路径为strPath="f:\test.txt"

code:

WriteData(objTCPCommandStream, "CWD " & strPath & vbCrLf)

....

Private Sub WriteData(ByVal NETStream As Object, ByVal sData As String)
bytWriting = System.Text.Encoding.ASCII.GetBytes(sData)
NETStream.Write(bytWriting, 0, bytWriting.Length)
End Sub


?????????????????????急急急急急
zl_xue 2003-11-27
  • 打赏
  • 举报
回复
谢谢,文章我看了!

可我要用上传到ftp服务器,saveas()不能实现这个功能!!他只能在物理路径!

udonome 2003-11-27
  • 打赏
  • 举报
回复
http://www.yesky.com/20011016/200942.shtml
zl_xue 2003-11-27
  • 打赏
  • 举报
回复
shit!
how can i finish this question!
where is the adv person here for .net ????????



zl_xue 2003-11-27
  • 打赏
  • 举报
回复
nobody have these fact code for me>>>>>????????

up myself
wwl1981 2003-11-27
  • 打赏
  • 举报
回复
up

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧