Results 1 to 17 of 17

Thread: COPY file from C:\ to ftp dir...

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    COPY file from C:\ to ftp dir...

    Possible copy a file from c:\ to a dir ftp server

    note:
    i just have usename and psword of ftp server

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: COPY file from C:\ to ftp dir...


  3. #3
    Addicted Member
    Join Date
    May 2012
    Location
    42.787034,-81.176367
    Posts
    130

    Re: COPY file from C:\ to ftp dir...

    Take Command Console from jpsoft.com allows you to copy a file from c:\ to a ftp server.

    You can download the free TCC Runtime.

    From a VB6 program, you can use SHELL to execute tcc runtime, and copy a file from c:\ to a ftp server.

    Examples:
    Code:
    copy ftp://ftp.abc.com/xyz/index index
    
    copy index ftp://ftp.abc.com/xyz/index
    Joe

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: COPY file from C:\ to ftp dir...

    Better yet use a modern server that supports secure and firewall-friendly WebDAV.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: COPY file from C:\ to ftp dir...

    experiment....

    Code:
    Option Explicit
    Private Sub CommandButton1_Click()
    
    Dim LocalPath As String
     Dim RemotePath As String
     
     LocalPath = "C:\EXPORT_CSV\sinc.csv"
     RemotePath = "/public_html/sinc.csv"
    
     With Inet1
     
       .AccessType = icDirect
       .Protocol = icFTP
     
       .UserName = "12345"
       .Password = "99999"
       .RemoteHost = "ftp.nard.it"
       
       .Execute .Url, "PUT " & LocalPath & " " & RemotePath
      
       While .StillExecuting
         DoEvents
       Wend
            
       .Execute , "CLOSE"
       
     End With
    
    End Sub
    the code, go to:

    .Execute , "CLOSE"

    but i have see via filezilla, the file exists in directori but the lenght of this is 0!!!!!!

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: COPY file from C:\ to ftp dir...

    Try this Codebank submission by Olaf Schmidt
    https://www.vbforums.com/showthread....Winsock-ocx%29

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: COPY file from C:\ to ftp dir...

    Quote Originally Posted by Arnoutdv View Post
    Try this Codebank submission by Olaf Schmidt
    https://www.vbforums.com/showthread....Winsock-ocx%29
    Tks for suggestion...
    but in:

    Code:
    ..........
    Private Sub Command1_Click()
        On Error Resume Next
        TreeView1.Nodes.Clear
        UserRootDirectory = ""
        Winsock1.Close: Winsock1.LocalPort = 0
        Winsock1.Connect Text4: DoEvents
    End Sub
    .............
    Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
        Dim i&, NodX As Node, NP$, NotReady As Boolean
        On Error Resume Next
        Node.Image = "Opened": Node.Expanded = True
        NP = Node.Parent.FullPath: If NP = "" Then NP = UserRootDirectory '<<<<<<<<< here error
        Do
            NotReady = False
            For Each NodX In TreeView1.Nodes
                If Len(NodX.FullPath) > Len(NP) And Node.Key <> NodX.Key Then
                    TreeView1.Nodes.Remove NodX.Key: NotReady = True: Exit For
                End If
            Next NodX
        Loop While NotReady
        Winsock1.SendData "CWD " & Replace(Node.FullPath, "//", "/") & vbCrLf
        ReadCurDir Len(Text1)
    End Sub
    ............
    have error 91 - object variable or with. block variable not set
    Last edited by luca90; Feb 25th, 2021 at 04:59 PM.

  8. #8
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: COPY file from C:\ to ftp dir...

    There is curl.exe shipped with every Win10 as a built-in utility nowadays.

    Btw, Inet control probably does not support *passive* mode.

    cheers,
    </wqw>

  9. #9
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

    Re: COPY file from C:\ to ftp dir...

    Technically, Windows Explorer supports FTP objects.

    If you create a shell item with an FTP url, you can drop files on it to upload. This is why my shell browser control can navigate FTP sites and drag/drop from them.

    Pretty sure a file copy with IFileOperation would work too.

  10. #10
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: COPY file from C:\ to ftp dir...

    Quote Originally Posted by luca90 View Post
    Tks for suggestion...
    but in:

    Code:
    ..........
    Private Sub Command1_Click()
        On Error Resume Next
        TreeView1.Nodes.Clear
        UserRootDirectory = ""
        Winsock1.Close: Winsock1.LocalPort = 0
        Winsock1.Connect Text4: DoEvents
    End Sub
    .............
    Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
        Dim i&, NodX As Node, NP$, NotReady As Boolean
        On Error Resume Next
        Node.Image = "Opened": Node.Expanded = True
        NP = Node.Parent.FullPath: If NP = "" Then NP = UserRootDirectory '<<<<<<<<< here error
        Do
            NotReady = False
            For Each NodX In TreeView1.Nodes
                If Len(NodX.FullPath) > Len(NP) And Node.Key <> NodX.Key Then
                    TreeView1.Nodes.Remove NodX.Key: NotReady = True: Exit For
                End If
            Next NodX
        Loop While NotReady
        Winsock1.SendData "CWD " & Replace(Node.FullPath, "//", "/") & vbCrLf
        ReadCurDir Len(Text1)
    End Sub
    ............
    have error 91 - object variable or with. block variable not set
    It’s a pity that after being a member for 16 years you don’t even know how to give information.
    I have to read the source lines to search for a comment about “error here”
    How is the variable declared, when is it set?
    Or did you copy a part of the sample code, but not everything what’s needed?

  11. #11
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

    Re: COPY file from C:\ to ftp dir...

    So my theory about IFileOperation working seems to be incorrect... kept saying "name invalid or too long" (which wasnt true)

    But dragdrop absolutely works, check this out:

    Code:
    Public Sub UploadToFTP(sFiles() As String)
    Dim siFTP As IShellItem
    Dim siItems As IShellItemArray
    Dim apidl() As Long
    Dim cpidl As Long
    Dim i As Long
    
    ReDim apidl(UBound(sFiles))
    
    For i = 0 To UBound(apidl)
        apidl(i) = ILCreateFromPathW(StrPtr(sFiles(i)))
    Next
    cpidl = UBound(apidl) + 1
    
    SHCreateShellItemArrayFromIDLists cpidl, VarPtr(apidl(0)), siItems
    
    SHCreateItemFromParsingName StrPtr("ftp://speedtest.tele2.net/upload/"), Nothing, IID_IShellItem, siFTP
    
    If (siItems Is Nothing) Or (siFTP Is Nothing) Then
        Debug.Print "Failed"
        Exit Sub
    End If
    
    Dim dtFTP As IDropTarget
    Dim doFiles As IDataObject
    
    siItems.BindToHandler 0&, BHID_DataObject, IID_IDataObject, doFiles
    siFTP.BindToHandler 0&, BHID_SFUIObject, IID_IDropTarget, dtFTP
    If (dtFTP Is Nothing) Or (doFiles Is Nothing) Then
        Debug.Print "no do/dt"
        Exit Sub
    End If
    dtFTP.DragEnter doFiles, 1&, 0&, 0&, DROPEFFECT_COPY
    dtFTP.Drop doFiles, 1&, 0&, 0&, DROPEFFECT_COPY
    End Sub
    You'd format the ftp url ftp://user:pass@ftpsite.com if you needed a username/password, and :port on the end if you need a port besides 21. .com:22

    (Requires a reference to oleexp.tlb and the addon module mIID.bas (included in the oleexp zip) for the IID/BHID values)

    Other ways are probably more practical, but thought this was a fun alternative.
    Last edited by fafalone; Feb 27th, 2021 at 01:14 AM.

  12. #12
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    460

    Re: COPY file from C:\ to ftp dir...

    ftp.exe can also take a script file as a param. Has been in windows since at least windows 2000.

    create a file called "commands.txt" and put the ftp commands inside

    Code:
    open ftp.yoursite.com
    user userNameHere
    passwordHere
    put yourFile.txt
    bye
    then shell it

    Code:
    shell("ftp.exe -s:c:\temp\commands.txt", vbnormalmode)

  13. #13
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: COPY file from C:\ to ftp dir...

    Unfortunately OS provided ftp.exe does not support PASV mode so upload will fail on 90% of public facing ftp servers.

    cheers,
    </wqw>

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: COPY file from C:\ to ftp dir...

    Quote Originally Posted by fafalone View Post
    So my theory about IFileOperation working seems to be incorrect... kept saying "name invalid or too long" (which wasnt true)

    But dragdrop absolutely works, check this out:

    Code:
    Public Sub UploadToFTP(sFiles() As String)
    Dim siFTP As IShellItem
    Dim siItems As IShellItemArray
    Dim apidl() As Long
    Dim cpidl As Long
    Dim i As Long
    
    ReDim apidl(UBound(sFiles))
    
    For i = 0 To UBound(apidl)
        apidl(i) = ILCreateFromPathW(StrPtr(sFiles(i)))
    Next
    cpidl = UBound(apidl) + 1
    
    SHCreateShellItemArrayFromIDLists cpidl, VarPtr(apidl(0)), siItems
    
    SHCreateItemFromParsingName StrPtr("ftp://speedtest.tele2.net/upload/"), Nothing, IID_IShellItem, siFTP
    
    If (siItems Is Nothing) Or (siFTP Is Nothing) Then
        Debug.Print "Failed"
        Exit Sub
    End If
    
    Dim dtFTP As IDropTarget
    Dim doFiles As IDataObject
    
    siItems.BindToHandler 0&, BHID_DataObject, IID_IDataObject, doFiles
    siFTP.BindToHandler 0&, BHID_SFUIObject, IID_IDropTarget, dtFTP
    If (dtFTP Is Nothing) Or (doFiles Is Nothing) Then
        Debug.Print "no do/dt"
        Exit Sub
    End If
    dtFTP.DragEnter doFiles, 1&, 0&, 0&, DROPEFFECT_COPY
    dtFTP.Drop doFiles, 1&, 0&, 0&, DROPEFFECT_COPY
    End Sub
    You'd format the ftp url ftp://user:pass@ftpsite.com if you needed a username/password, and :port on the end if you need a port besides 21. .com:22

    (Requires a reference to oleexp.tlb and the addon module mIID.bas (included in the oleexp zip) for the IID/BHID values)

    Other ways are probably more practical, but thought this was a fun alternative.
    hi bro...
    i dont see the path where i can store the file from c:\mydir...

    in other case the my parameter are store in a const:

    Public Const SERVERFTP = "ftp.my.it"
    Public Const USERNAME = "1234"
    Public Const PSW = "999999"
    Public Const LOCDIR = "C:\mydir"
    Public Const FTPDIR = "/public_html/dir1"
    Public Const CSVFILE = "sinc.csv"

  15. #15
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: COPY file from C:\ to ftp dir...

    Quote Originally Posted by wqweto View Post
    Unfortunately OS provided ftp.exe does not support PASV mode so upload will fail on 90% of public facing ftp servers.

    cheers,
    </wqw>
    Really? hmm that seems off given that I have been using it to upload files to ftp servers for the last 20 years or so, always worked fine for me.

  16. #16
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: COPY file from C:\ to ftp dir...

    Quote Originally Posted by DataMiser View Post
    Really? hmm that seems off given that I have been using it to upload files to ftp servers for the last 20 years or so, always worked fine for me.
    Hint: try ftp.exe pasv mode in google.

    Not sure if they upgraded this in Win10 and not sure if PASV mode is used for upload at all or for download only. Certainly ftp.exe is pretty useless impl of the protocol provided that they now include curl.exe in stock OS.

  17. #17
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

    Re: COPY file from C:\ to ftp dir...

    Quote Originally Posted by luca90 View Post
    hi bro...
    i dont see the path where i can store the file from c:\mydir...

    in other case the my parameter are store in a const:

    Public Const SERVERFTP = "ftp.my.it"
    Public Const USERNAME = "1234"
    Public Const PSW = "999999"
    Public Const LOCDIR = "C:\mydir"
    Public Const FTPDIR = "/public_html/dir1"
    Public Const CSVFILE = "sinc.csv"
    You'd call it like this:
    Code:
    Dim sFile() As String
    ReDim sFile(0)
    sFile(0) = "C:\mydir\sinc.csv"
    UploadToFTP sFile
    And modify the UploadToFTP address like ftp://1234:999999@ftp.my.it/public_html/dir1/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width