以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  ftp文件上传判断  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=96690)

--  作者:cuicuibing
--  发布时间:2017/2/26 14:27:00
--  ftp文件上传判断
Dim ftp1 As New FtpClient
Ftp1.Host = ""
Ftp1.Account = ""
Ftp1.Password = ""
Dim proDir As String = Tables("a").Current("第一类")
Dim dlg As New OpenFileDialog
dlg.Filter= "图形文件|*.bmp;*.jpg;*.gif"
dlg.MultiSelect = True
If dlg.ShowDialog = DialogResult.OK Then
    Dim fpath As String =  "/a/" & prodir & "/"
    Dim str As String = Tables("a").Current("第二列")
    For Each fl As String In dlg.FileNames
        \'Dim fileInfo As new FileInfo(fl)
        If ftp1.FileExists(fpath & filesys.GetName(fl)) Then
            Messagebox.show("同名文件","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
         判断重名后,这里如何将上传的自动改名为原文件名+   -1  ,并判断文件名是否重复,如果不重复 上传,如果重复自动
         +   -2   一次类推

                                   或者有自动重命名的其他方式

           If Ftp1.Upload(,,True) = True Then
           str &= fpath & FileSys.GetName(fl) & vbcrlf   --这里的路径保存
        Else
            If Ftp1.Upload(fl,fpath & filesys.GetName(fl),True) = True Then
                str &= fpath & FileSys.GetName(fl) & vbcrlf
                 Messagebox.show("上传完成!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
            Else
                Messagebox.show("上传失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                
            End If
        End If
    Next
    Tables("a").Current("第二列")= str
    Tables("a").Current.Save()
End If

[此贴子已经被作者于2017/2/26 14:29:27编辑过]

--  作者:有点色
--  发布时间:2017/2/26 15:14:00
--  
Dim i As Integer = 1
Do While ftp1.FileExists(fpath & filesys.GetName(fl) & i)
    Messagebox.show("同名文件","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    i = i + 1
Loop
If Ftp1.Upload(fl, fpath & filesys.GetName(fl) & i, True) = True Then
    str &= fpath & FileSys.GetName(fl) & i vbcrlf   --这里的路径保存
End If

--  作者:cuicuibing
--  发布时间:2017/2/26 15:29:00
--  
感谢版主   这里不对。

测试一下,上传的是   aaa.jpg

重命名的为  aaa.jpg1

--  作者:cuicuibing
--  发布时间:2017/2/26 15:36:00
--  
图片这样也可以显示?

实际确实可以显示

--  作者:有点色
--  发布时间:2017/2/26 17:22:00
--  

改一下

 

Dim i As Integer = 1
Dim finfo As new fileinfo(fl)
Dim name As String = fpath & finfo.Name.replace(finfo.Extension, "") & i & finfo.Extension
Do While ftp1.FileExists(name)
    Messagebox.show("同名文件","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    i = i + 1
    name = fpath & finfo.Name.replace(finfo.Extension, "") & i & finfo.Extension
Loop
If Ftp1.Upload(fl, name, True) = True Then
    str &= name & vbcrlf   --这里的路径保存
End If