标题:[求助]使用wininet编写FTP上传照片程序,老是上传失败
只看楼主
zoglag
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-6-15
 问题点数:0 回复次数:0 
[求助]使用wininet编写FTP上传照片程序,老是上传失败
    本人用wininet做一个用于上传照片到FTP服务器的程序,但是经常会出现上传失败,失败后会在FTP服务器上留下一个0字节的文件,删除会提示“在服务器上打开”。
以下是我用来上传的程序代码,求助各位帮忙分析下原因,该如何解决。

程序代码:
Private Function PutImg(n As Integer) 'n为要上传的文件数
'上传照片
Dim ftpurl As String
Dim foldes As String
Dim isput As Boolean
Dim i As Integer
i = n - 1
Do While i >= 0 
  foldes = "/" & camera & "/" & List3.List(i) & "/" '生成照片上传目标路径,对应相机文件夹,list3用来存放文件夹名称
  Call c.CreatFolde(foldes) '在服务器上新建文件夹,没有则新建
  ftpurl = foldes & List2.List(i) '生成完整路径,包括上传后保持原文件名,list2为文件名
  isput = c.PutImg(List1.List(i), ftpurl) '上传照片,list1存放本地文件路径
  If isput = False Then
    isput = c.PutImg(List1.List(i), ftpurl) '重新上传照片
    if isput=false then exit do
  End If
  DoEvents
  i = i - 1
Loop
end function

'以下是clsftp内容
Private 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
Private 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
Private 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
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hinet As Long) As Integer
Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (ByVal hFtpSession&, ByVal lpszDirectory$) As Boolean
Dim linkOn  As Boolean 
Dim hSession  As Long 

Public Function FtpConnect(Optional ByVal Host$ = vbNullString, _
    Optional ByVal Port& = 0, _
    Optional ByVal user$ = vbNullString, _
    Optional ByVal Password$ = vbNullString) As Boolean
    hinet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0&)
    hSession = InternetConnect(hinet, Host$, Port&, user$, Password$, 1, 0, 0)
    If hSession > 0 Then
      linkOn = True
    Else
      linkOn = False
    End If
    FtpConnect = linkOn
End Function
                                                                   
Public Function PutImg(path As String, ftpurl As String) As Boolean
  If linkOn = True Then
   PutImg = FtpPutFile(hSession, path, ftpurl, 1, 0)
  End If
End Function
                                                                   
Public Function CreatFolde(ByVal path As String) As String
   CreatFolde = FtpCreateDirectory(hSession, path)
End Function


[此贴子已经被作者于2017-8-29 15:04编辑过]

搜索更多相关主题的帖子: 上传 Function String ByVal Long 
2017-08-29 15:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-480349-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.224127 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved