以文本方式查看主题

-  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=110765)

--  作者:yifan3429
--  发布时间:2017/12/8 21:36:00
--  文件保存到FTP服务器
If e.Col.name = "图片" Then
    baseMainForm.WindowState= Windows.forms.FormWindowState.Minimized
    ClipBoard.Clear
    Dim proc As new Process
    proc.File = ApplicationPath & "/capture.exe"
    proc.WaitForClose = True
    proc.Start
    If ClipBoard.GetImage IsNot Nothing Then
        Dim f As String =  e.Row("客户名称") & "\\"  & e.Row("楼层")& "\\"  & "3.报价配图"  & "\\" & Format( Date.Today,"yyyy-MM-dd") & "\\"& e.Row("产品名") &"-" & e.Row("产品号")&".png"
        Dim path As String = e.Col.DataCol.DefaultFolder
        If path = "" Then
           
            path = Vars("IPM")
            
        End If
        basemainform.WindowState = 2
        Dim dir As String = FileSys.GetParentPath(path & "/" & f)
        If FileSys.DirectoryExists(dir) = False Then FileSys.CreateDirectory(dir)
        ClipBoard.GetImage.save(path & "/" & f)
        e.Row(e.Col.name) = f
    End If
    e.cancel = True
    Tables("订单总表.订单明细").Current.Save() \'保存文件的行
    End If

我想将截屏文件直接保存到FTP服务器  可以吗  代码怎样编辑

--  作者:有点蓝
--  发布时间:2017/12/8 22:09:00
--  
If e.Col.name = "图片" Then
    baseMainForm.WindowState= Windows.forms.FormWindowState.Minimized
    ClipBoard.Clear
    Dim proc As new Process
    proc.File = ApplicationPath & "/capture.exe"
    proc.WaitForClose = True
    proc.Start
    If ClipBoard.GetImage IsNot Nothing Then
        Dim f As String =  e.Row("客户名称") & "\\"  & e.Row("楼层")& "\\"  & "3.报价配图"  & "\\" & Format( Date.Today,"yyyy-MM-dd") & "\\"& e.Row("产品名") &"-" & e.Row("产品号")&".png"
        Dim path As String = e.Col.DataCol.DefaultFolder
        If path = "" Then
            
            path = Vars("IPM")
            
        End If
        basemainform.WindowState = 2
        Dim dir As String = FileSys.GetParentPath(path & "/" & f)
        If FileSys.DirectoryExists(dir) = False Then FileSys.CreateDirectory(dir)
        ClipBoard.GetImage.save(path & "/" & f)
        e.Row(e.Col.name) = f
        Dim  ftp1 As  New  FtpClient
        ftp1.Host="196.128.143.28"
        ftp1.Account =  "foxuser"
        ftp1.Password =  "138238110"
        If  ftp1.Upload(path & "/" & f,f) = True Then
            Messagebox.show("上传完成!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        Else
            Messagebox.show("上传失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        End If
    End If
    e.cancel = True
    Tables("订单总表.订单明细").Current.Save() \'保存文件的行
End If

[此贴子已经被作者于2017/12/8 22:10:01编辑过]

--  作者:yifan3429
--  发布时间:2017/12/8 22:50:00
--  
If e.Col.name = "图片" Then
    baseMainForm.WindowState= Windows.forms.FormWindowState.Minimized
    ClipBoard.Clear
    Dim proc As new Process
    proc.File = ApplicationPath & "/capture.exe"
    proc.WaitForClose = True
    proc.Start
    If ClipBoard.GetImage IsNot Nothing Then
        Dim f As String =  e.Row("客户名称") & "\\"  & e.Row("楼层")& "\\"  & "3.报价配图"  & "\\" & Format( Date.Today,"yyyy-MM-dd") & "\\"& e.Row("产品名") &"-" & e.Row("产品号")&".png"
        Dim path As String = e.Col.DataCol.DefaultFolder
        If path = "" Then
            
            path = Vars("IPM")     文件还是存到我的这个本地地址 没有上传到 FTP、
            
        End If
        basemainform.WindowState = 2
        Dim dir As String = FileSys.GetParentPath(path & "/" & f)
        If FileSys.DirectoryExists(dir) = False Then FileSys.CreateDirectory(dir)
        ClipBoard.GetImage.save(path & "/" & f)
        e.Row(e.Col.name) = f
        Dim  ftp1 As  New  FtpClient
        ftp1.Host="196.128.143.28"
        ftp1.Account =  "foxuser"
        ftp1.Password =  "138238110"
        If  ftp1.Upload(path & "/" & f,f) = True Then
            Messagebox.show("上传完成!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        Else
            Messagebox.show("上传失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        End If
    End If
    e.cancel = True
    Tables("订单总表.订单明细").Current.Save() \'保存文件的行
End If

--  作者:有点蓝
--  发布时间:2017/12/8 23:02:00
--  
改为自己的ftp的地址和用户,以及上传的路径。下面代码运行后提示成功还是失败?

Dim  ftp1 As  New  FtpClient
        ftp1.Host="196.128.143.28"
        ftp1.Account =  "foxuser"
        ftp1.Password =  "138238110"
        If  ftp1.Upload(path & "/" & f,f) = True Then
            Messagebox.show("上传完成!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        Else
            Messagebox.show("上传失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        End If

--  作者:yifan3429
--  发布时间:2017/12/8 23:21:00
--  
提示失败
--  作者:有点蓝
--  发布时间:2017/12/9 8:37:00
--  
直接打开管理器能不能打开?
Dim  ftp1 As  New  FtpClient
ftp1.Host="196.128.143.28"
ftp1.Account =  "foxuser"
ftp1.Password =  "138238110"
ftp1.OpenManager

这样呢?
Dim  ftp1 As  New  FtpClient
ftp1.Host="196.128.143.28"
ftp1.Account =  "foxuser"
ftp1.Password =  "138238110"
If  ftp1.Upload(path & "\\" & f, "/" & f) = True Then
    Messagebox.show("上传完成!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Else
    Messagebox.show("上传失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

--  作者:yifan3429
--  发布时间:2017/12/9 21:24:00
--  
地址测试正常  就是提示上传失败

If e.Col.name = "图片" Then
    baseMainForm.WindowState= Windows.forms.FormWindowState.Minimized
    ClipBoard.Clear
    Dim proc As new Process
    proc.File = ApplicationPath & "/capture.exe"
    proc.WaitForClose = True
    proc.Start
    If ClipBoard.GetImage IsNot Nothing Then
        Dim f As String =  e.Row("客户名称") & "\\"  & e.Row("楼层")& "\\"  & "3.报价配图"  & "\\" & Format( Date.Today,"yyyy-MM-dd") & "\\"& e.Row("产品名") &"-" & e.Row("产品号")&".png"
        Dim path As String = e.Col.DataCol.DefaultFolder
        If path = "" Then
            
            path = Vars("IPM")   现在文件会存到我这个本地地址  不会上传到ftp
            
        End If
        basemainform.WindowState = 2
        Dim dir As String = FileSys.GetParentPath(path & "/" & f)
        If FileSys.DirectoryExists(dir) = False Then FileSys.CreateDirectory(dir)
        ClipBoard.GetImage.save(path & "/" & f)
        e.Row(e.Col.name) = f
        Dim  ftp1 As  New  FtpClient
        ftp1.Host="47.95.20"
        ftp1.Account =  "foxftp"
        ftp1.Password =  "Yi8"
        If  ftp1.Upload(path & "/" & f,f) = True Then
            
            \'If  ftp1.Upload(path & "\\" & f, "/" & f) = True Then
            Messagebox.show("上传完成!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        Else
            Messagebox.show("上传失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        End If
    End If
    e.cancel = True
    Tables("订单总表.订单明细").Current.Save() \'保存文件的行
End If
[此贴子已经被作者于2017/12/9 21:25:37编辑过]

--  作者:有点甜
--  发布时间:2017/12/10 16:08:00
--  

路径必须存在才能上传的。如果不存在,必须创建

 


Dim path As String = ""

Dim file As String = e.Row("客户名称") & "\\"  & e.Row("楼层")& "\\"  & "3.报价配图"  & "\\" & Format( Date.Today,"yyyy-MM-dd")
For Each s As String In file.split("\\")
    path = path & "/" & s
    If ftp1.DirExists(path) = False Then
        ftp1.MakeDir(path)
    End If
Next

If  ftp1.Upload(path & "/" & f,f) = True Then


--  作者:yifan3429
--  发布时间:2017/12/11 13:02:00
--  
If e.Col.name = "图片" Then
    baseMainForm.WindowState= Windows.forms.FormWindowState.Minimized
    ClipBoard.Clear
    Dim proc As new Process
    proc.File = ApplicationPath & "/capture.exe"
    proc.WaitForClose = True
    proc.Start
    If ClipBoard.GetImage IsNot Nothing Then
        Dim f As String =  e.Row("客户名称") & "\\"  & e.Row("楼层")& "\\"  & "3.报价配图"  & "\\" & Format( Date.Today,"yyyy-MM-dd") & "\\"& e.Row("产品名") &"-" & e.Row("产品号")&".png"
        Dim path As String = e.Col.DataCol.DefaultFolder
        If path = "" Then
            
            path = Vars("IPM")
            
        End If
        basemainform.WindowState = 2
        Dim dir As String = FileSys.GetParentPath(path & "/" & f)
        If FileSys.DirectoryExists(dir) = False Then FileSys.CreateDirectory(dir)
        ClipBoard.GetImage.save(path & "/" & f)
        e.Row(e.Col.name) = f
        Dim  ftp1 As  New  FtpClient
        ftp1.Host="47.0"
        ftp1.Account =  "foftp"
        ftp1.Password =  "Y08"
        Dim path As String = ""
        Dim file As String = e.Row("客户名称") & "\\"  & e.Row("楼层")& "\\"  & "3.报价配图"  & "\\" & Format( Date.Today,"yyyy-MM-dd")
        For Each s As String In file.split("\\")
            path = path & "/" & s
            If ftp1.DirExists(path) = False Then
                ftp1.MakeDir(path)
            End If
        Next
        If  ftp1.Upload(path & "/" & f,f) = True Then
            
            \'If  ftp1.Upload(path & "\\" & f, "/" & f) = True Then
            Messagebox.show("上传完成!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        Else
            Messagebox.show("上传失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        End If
    End If
    e.cancel = True
    Tables("订单总表.订单明细").Current.Save() \'保存文件的行
End If

这样吗  就是会同时保存在本地和ftp上

--  作者:有点甜
--  发布时间:2017/12/11 14:25:00
--  

现在执行同样报错不能上传?下面代码弹出什么?

 

msgbox(ftp1.DirExists("/" & file))

 

msgbox(ftp1.DirExists("/" & file.replace("\\", "/")))