vb登录ftp服务器并打开文档,VB.Net实现登陆Ftp的方法
开发环境 VB.Net2005 Windows2003
'调用方式
If Logined() Then
MsgBox("登陆成功")
Else
MsgBox("登陆失败")
End If
'功能函数
Imports System
Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Net.Sockets
Public Const BLOCK_SIZE = 512
Private Obj_ClientSocket As Socket
Private Str_Domain As String = "ftp.lob.cn" 'ftp服务器地址
Private Str_User As String = "lob" 'ftp登陆帐号
Private Str_Password As String = "www.lob.cn" 'ftp登陆密码
Private Int_RemotePort As Integer = 21 'ftp服务器端口
Private Int_Reply, Int_Bytes As Int32
Private Str_Message, Str_Reply As String
Private Byte_Buffer(BLOCK_SIZE) As Byte
Private ASCII As Encoding = Encoding.ASCII
Public Function Logined() As Boolean '乐博网www.lob.cn会员逍遥原创
Obj_ClientSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Dim x_lob As New IPEndPoint(Dns.GetHostEntry(Str_Domain).AddressList(0), Int_RemotePort)
Try
Obj_ClientSocket.Connect(x_lob)
Catch ex As Exception
MsgBox("无法登陆远程Ftp服务器")
End Try
Str_Message = ""
Str_Reply = ServerReply()
Int_Reply = Int32.Parse(Str_Reply.Substring(0, 3))
If (Int_Reply 220) Then
MsgBox(Str_Reply.Substring(4))
End If
SendCommand("USER " & Str_User)
Str_Reply = ServerReply(True)
Int_Reply = Int32.Parse(Str_Reply.Substring(0, 3))
If (Not (Int_Reply = 331 Or Int_Reply = 230)) Then
MsgBox(Str_Reply.Substring(4) )
Return False
End If
If (Int_Reply 230) Then
SendCommand("PASS " & Str_Password)
Str_Reply = ServerReply(True)
Int_Reply = Int32.Parse(Str_Reply.Substring(0, 3))
If (Not (Int_Reply = 230 Or Int_Reply = 202)) Then
MsgBox(Str_Reply.Substring(4))
Return False
End If
End If
Return True
End Function
Private Function ServerReply(Optional ByVal Bool_Clear As Boolean = False) As String
Dim Sep As Char = ControlChars.Lf
Dim Arr_Msg() As String
If (Bool_Clear) Then
Str_Message = ""
End If
Do While (True)
Array.Clear(Byte_Buffer, 0, BLOCK_SIZE)
Int_Bytes = Obj_ClientSocket.Receive(Byte_Buffer, Byte_Buffer.Length, 0)
Str_Message += ASCII.GetString(Byte_Buffer, 0, Int_Bytes)
If (Int_Bytes < Byte_Buffer.Length) Then
Exit Do
End If
Loop
Arr_Msg = Str_Message.Split(Sep)
If (Str_Message.Length > 2) Then
Str_Message = Arr_Msg(Arr_Msg.Length - 2)
Else
Str_Message = Arr_Msg(0)
End If
If (Not (Str_Message.Substring(3, 1).Equals(" "))) Then
Return ServerReply(True)
End If
Return Str_Message
End Function
Private Sub SendCommand(ByVal Str_Command As String)
Str_Command = Str_Command & ControlChars.CrLf
Dim cmdbytes As Byte() = ASCII.GetBytes(Str_Command)
Obj_ClientSocket.Send(cmdbytes, cmdbytes.Length, 0)
End Sub
vb登录ftp服务器并打开文档,VB.Net实现登陆Ftp的方法相关推荐
- 用win7系统如何登录ftp服务器,必备技巧之最详细win7系统登陆ftp服务器的图文教程...
FTP服务器是什么呢?FTP服务器(File Transfer Protocol Server)是在互联网上提供文件存储和访问服务的计算机,它们依照FTP协议提供服务. 那么如何在win7系统登陆ft ...
- ftp服务器批量上传文件,bat批量上传ftp文件到服务器
bat批量上传ftp文件到服务器 内容精选 换一换 CDM支持周期性自动将新增文件上传到OBS,不需要写代码,也不需要用户频繁手动上传即可使用OBS的海量存储能力进行文件备份.这里以CDM周期性备份F ...
- Office 2013 Excel 打开文档很慢很慢的解决方法
Office 2013 Excel 打开文档很慢很慢的解决方法 参考文章: (1)Office 2013 Excel 打开文档很慢很慢的解决方法 (2)https://www.cnblogs.com/ ...
- ftp服务器中的文档不能直接打开为啥,如何直接打开ftp里的 word 文档 win7 ftp直接打开word...
ftp不能直接打开word我的电脑不能在ftp上直接打开文件,其 在浏览器中输入ftp地址,不能显示文件夹视图. 但是可以在资源管理器的地址栏输入地址后打开. 打开IE的工具,找到Internet选项 ...
- 如何设置ftp服务器上传文件夹至不同路径,设置ftp服务器上传文件夹
设置ftp服务器上传文件夹 内容精选 换一换 上传单个或多个本地文件或文件夹至OBS指定路径.待上传的文件可以是任何类型:文本文件.图片.视频等等.上传本地文件或文件夹时,请确保本地文件或文件夹在上传 ...
- python ftp服务器限速_用 Python 快速实现 HTTP 和 FTP 服务器
用 Python 快速实现 HTTP 服务器 有时你需临时搭建一个简单的 Web Server,但你又不想去安装 Apache.Nginx 等这类功能较复杂的 HTTP 服务程序时.这时可以使用 Py ...
- linux搭建ftp服务器可上传下载,通过linux系统搭建ftp服务然后使用filezilla客户端进行上传下载...
1. 准备环境 一台linux主机作为ftp服务器(这里以centos7.2系统为例),一台Windows系统的主机作为客户端 2. 服务端配置: (1) 下载vs ...
- 哪种ftp服务器最稳定,ftp服务器软件,推荐三款值得推荐的ftp服务器软件
ftp服务器软件主要是网络上用来传送文件的工具.但有些ftp服务器软件传输文件不是特别稳定.今天就来为大家推荐四款值得推荐的ftp服务器软件. 第一款:IIS7服务器管理工具 这款软件的Ftp客户端做 ...
- 软路由ftp服务器搭建网站,应用开源软件FileZilla Server架设FTP服务器
FileZillaServer是一款非常流行的开源FTP服务器软件,相对于常用的FTP服务器软件Serv-U,FileZillaServer的主要优势在于:高安全性.高性能.完全开源.完全免费.简单易 ...
最新文章
- errors'MessageBoxA' : function does not take 1 parameter
- backup(full,diff,log)备份并清理过时备份
- Mysql---Centos7软件安装
- hashmap的get查找过程
- 安装OpenResty,实现分发层、应用层nginx+lua开发(附加问题:bad argument #2 to ‘set_keepalive‘ (number expected, got nil)
- azm335x 串口配置
- 性能测试oracle瓶颈定位,性能测试中如何定位性能瓶颈
- 如何在读研读博的道路上迅速失败?
- 巧用 Img / JavaScript 采集页面数据
- gcc编译以及Makefile与GDB调试
- Kafka-batch.size属性
- 三维数组怎么排列_【连载5.3】三维测量算法GPU实现
- Intel 芯片集被曝漏洞,可导致加密数据被盗
- 如何做数据库分页查询
- 《哪吒》刷爆全网:不认命,就是我选择的命!做自己命运的主宰!
- 探访IBM企业级区块链-CSDN公开课-专题视频课程
- 汇编“从键盘输入一串字符,分别统计其中字母、数字和其
- 一对一视频直播源码|手机视频直播平台android源码/可打包视频直播
- 计算机图形学 裁剪算法源代码,OpenGL计算机图形学梁友栋裁剪算法实验代码及运行结果.doc...
- 小白记录:1、scrapy的基础操作