[VB]为什么只能上传到FTP的根目录?
根据自定义过程,执行UploadFileToFTP Inet1, "ftp://space1.xinwen365.com/tmp", "c:\a.html", "space1", "123456", msg以把a.html上传到ftp://space1.xinwen365.com/tmp,但反回错误信息是:不能连接到远程计算机,然后把ftp://space1.xinwen365.com/tmp改成ftp://space1.xinwen365.com/也是这个信息。*******自定义过程如下面*在执行 ftp://space1.xinwen365.com/tmp之前能把文件传到ftp://space1.xinwen365.com/,所以函数过程是可运行的*tmp文件夹存在,网络连接完好Public Sub UploadFileToFTP( _InetObject As inet, _FTPServerAddress As String, _PathAndFilename As String, _AdminName As String, _Password As String, _Optional MessageReturn As String)'上传文件:'需要Inet控件On Error GoTo DealerrInetObject.Protocol = icFTPInetObject.RemoteHost = FTPServerAddress 'ServerName '服务器地址InetObject.RemotePort = 21 'FTP端口InetObject.UserName = AdminName '用户名InetObject.Password = Password '密码'InetObject.Execute "", "PUT d:\1.txt 1.txt"InetObject.Execute "", "PUT " & PathAndFilename & Space$(1) & GetFileName(PathAndFilename)Dim ri As Longri = InetObject.StillExecutingDo While riri = InetObject.StillExecutingDoEventsLoopExit SubDealerr:MessageReturn = "Error:" & Error$(Err)Exit SubEnd SubPrivate Function GetFileName(PathAndFilename As String) As String'去掉文件路径,保留文件名Dim tmp As Stringtmp = Trim(PathAndFilename)Dim a As IntegerDoa = InStr(tmp, "\")tmp = Right(tmp, Len(tmp) - a)Loop Until a = 0GetFileName = tmpEnd Function
参考答案:我这样用inet访问ftp:
With Inet1 '设置ftp信息
.URL = ftp://ftp1.go.163.com '服务器地址
.UserName = "username" '用户名
.Password = "password"
End With
Inet1.Execute , "put c:\temp\vbbs\msglst.dat /msglst.dat" '上传列表文件
Call waitftpdone
Inet1.Execute , "put c:\temp\vbbs\" + CStr(LastRecord) + ".txt" + " /msg/" + CStr(LastRecord) + ".txt" '上传留言正文
Call waitftpdone
Inet1.Execute , "close" '关闭连接,此过程必不可少!
Call waitftpdone
以上。
回忆的老狼