Results 1 to 23 of 23

Thread: Send Data to FTP without using any OCX ?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Send Data to FTP without using any OCX ?

    Hello ,

    is there anyway to send data to FTP without using any OCX like Winsock or MSINET ?

    Thanks

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Send Data to FTP without using any OCX ?

    you can do it quite easily using the ftp and internet API functions
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Send Data to FTP without using any OCX ?

    Quote Originally Posted by westconn1
    you can do it quite easily using the ftp and internet API functions
    do you a simple code ?

    Thanks

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Send Data to FTP without using any OCX ?

    in the general section
    vb Code:
    1. Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
    2. Const FTP_TRANSFER_TYPE_ASCII = &H1
    3. Const FTP_TRANSFER_TYPE_BINARY = &H2
    4. Const INTERNET_DEFAULT_FTP_PORT = 21               ' default for FTP servers
    5. Const INTERNET_SERVICE_FTP = 1
    6. Const INTERNET_FLAG_PASSIVE = &H8000000            ' used for FTP connections
    7. Const INTERNET_OPEN_TYPE_PRECONFIG = 0                    ' use registry configuration
    8. Const INTERNET_OPEN_TYPE_DIRECT = 1                        ' direct to net
    9. Const INTERNET_OPEN_TYPE_PROXY = 3                         ' via named proxy
    10. Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4   ' prevent using java/script/INS
    11. Const MAX_PATH = 260
    12. Private Type FILETIME
    13.     dwLowDateTime As Long
    14.     dwHighDateTime As Long
    15. End Type
    16. Private Type WIN32_FIND_DATA
    17.     dwFileAttributes As Long
    18.     ftCreationTime As FILETIME
    19.     ftLastAccessTime As FILETIME
    20.     ftLastWriteTime As FILETIME
    21.     nFileSizeHigh As Long
    22.     nFileSizeLow As Long
    23.     dwReserved0 As Long
    24.     dwReserved1 As Long
    25.     cFileName As String * MAX_PATH
    26.     cAlternate As String * 14
    27. End Type
    28. Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
    29. 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
    30. 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
    31. Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
    32. Private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String, lpdwCurrentDirectory As Long) As Long
    33. Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
    34. Private Declare Function FtpRemoveDirectory Lib "wininet.dll" Alias "FtpRemoveDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
    35. Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
    36. Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" (ByVal hFtpSession As Long, ByVal lpszExisting As String, ByVal lpszNew As String) As Boolean
    37. Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hConnect As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Long, ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByRef dwContext As Long) As Boolean
    38. Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
    39. Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (lpdwError As Long, ByVal lpszBuffer As String, lpdwBufferLength As Long) As Boolean
    40. Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long
    41. Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
    42. Const PassiveConnection As Boolean = True
    43.  
    44. Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

    in a command button or similar
    vb Code:
    1. Dim session As Long, server As Long, ftpserver As String, user As String, pass As String
    2. Dim ret As Long, localfile As String, remotefile As String, pic As String
    3. ftpserver = ""  'server
    4. user = ""   ' username
    5. pass = ""   ' passsword
    6. localfile = App.Path & "\test.htm"
    7. remotefile = LCase(List1.Text) & ".html"
    8. If List1.Text = "Blogs" Then blog  ' put comments box code
    9.  
    10. If vbNo = MsgBox("Do you wish to upload the page you previewed to the " & List1.Text & " folder on the website", vbYesNo, "Upload?") Then Unload Me: Exit Sub
    11. Me.MousePointer = vbHourglass
    12. Me.Caption = "Uploading..........."
    13. 'session = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, INTERNET_FLAG_NO_CACHE_WRITE)
    14. 'server = InternetConnect(session, ftpserver, INTERNET_INVALID_PORT_NUMBER, user, pass, 1, 0, 0)
    15. session = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, INTERNET_FLAG_NO_CACHE_WRITE)
    16. server = InternetConnect(session, ftpserver, INTERNET_INVALID_PORT_NUMBER, user, pass, 1, INTERNET_FLAG_PASSIVE, 0)
    17.  
    18. 'session = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, INTERNET_FLAG_NO_CACHE_WRITE)
    19. 'server = InternetConnect(session, ftpserver, INTERNET_INVALID_PORT_NUMBER, user, pass, 1, INTERNET_FLAG_PASSIVE, 0)
    20.     Dim pData As WIN32_FIND_DATA, hFind As Long, lRet As Long, mypath As String
    21.     'set the graphics mode to persistent
    22. ''    Me.AutoRedraw = True
    23.     'create a buffer
    24.     pData.cFileName = String(MAX_PATH, 0)
    25.     'find the first file
    26.     hFind = FtpFindFirstFile(server, "*.", pData, 0, 0)
    27. mypath = String(MAX_PATH, 0)
    28. FtpGetCurrentDirectory server, mypath, Len(mypath)
    29. ret = FtpSetCurrentDirectory(server, "/www/" & LCase(List1.Text))
    30. 'ret = FtpSetCurrentDirectory(server, List1.Text)
    31. 'mypath = Space(255)
    32. If Not ret = 0 Then
    33.     ret = FtpPutFile(server, localfile, remotefile, FTP_TRANSFER_TYPE_BINARY, 0)
    34.     If Not ret = 1 Then MsgBox localfile & " failed to upload"
    35.     pic = Dir(App.Path & "\pic*.jpg")
    36.     Do While Len(pic) > 0
    37.         ret = FtpPutFile(server, App.Path & "\" & pic, pic, FTP_TRANSFER_TYPE_BINARY, 0)
    38.         If Not ret = 1 Then MsgBox App.Path & "\" & pic & " failed to upload"
    39.         pic = Dir
    40.     Loop
    41. End If
    42. InternetCloseHandle server
    43. InternetCloseHandle session
    44. Me.MousePointer = vbNormal
    45. MsgBox "uploading complete"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Send Data to FTP without using any OCX ?

    hi westconn1 ,
    sorry for been too late
    but i tried your code & didnt work for me
    i have no error but i havent received my File in FTP

    Thanks
    Last edited by killer7k; Jul 1st, 2008 at 07:12 AM.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Send Data to FTP without using any OCX ?

    this line
    ret = FtpSetCurrentDirectory(server, "/www/" & LCase(List1.Text))
    sets the destination folder, you must change that to a valid folder on your ftp server and you need to have set the username and password etc
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Send Data to FTP without using any OCX ?

    sorry but dont work for me i set it to the root directly
    i have done all tips but no it say uploading complete but i cant find anything
    if you could try a simple file from your hardrive & send it to ftp to the root
    & replay to me

    Thanks

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Send Data to FTP without using any OCX ?

    here you my last code

    Code:
    Private Sub Form_Load()
     
         Dim hConnection As Long, hOpen As Long, sOrgPath As String
    'open an internet connection
    hOpen = InternetOpen("API-Guide sample program", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
    'connect to the FTP server
    hConnection = InternetConnect(hOpen, "ftp://....", INTERNET_DEFAULT_FTP_PORT, "...", "....", INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
    'create a buffer to store the original directory
    sOrgPath = String(MAX_PATH, 0)
    'get the directory
    FtpGetCurrentDirectory hConnection, sOrgPath, Len(sOrgPath)
    'create a new directory 'test'
    FtpCreateDirectory hConnection, "test"
    'set the current directory to 'root/test'
    FtpSetCurrentDirectory hConnection, "test"
    
    'upload the file 
    FtpPutFile hConnection, "C:\\setup.log", "setup.log", FTP_TRANSFER_TYPE_BINARY, 0
    
    'close the FTP connection
    InternetCloseHandle hConnection
    'close the internet connection
    InternetCloseHandle hOpen
    End Sub

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Send Data to FTP without using any OCX ?

    if you want me to help more pm me with your ftp server, login and password, and i will test the code to make sure it works to your server

    the code i posted is the exact code i use for one specific connection
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Send Data to FTP without using any OCX ?

    i dont think that there is a problem with ftp
    because i was using Msinet & working well
    i just want you if its possible of course to create a simple txt file in your harddrive & send it to ftp directly to root path using only FtpPutFile
    try it plz & show me your code

    Thanks

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Send Data to FTP without using any OCX ?

    vb Code:
    1. Dim session As Long, server As Long, ftpserver As String, user As String, pass As String
    2. Dim ret As Long, localfile As String, remotefile As String
    3. ftpserver = ""
    4. user = ""
    5. pass = ""
    6. localfile = App.Path & "\" & fname
    7. remotefile = fname
    8.  
    9. session = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, INTERNET_FLAG_NO_CACHE_WRITE)
    10. server = InternetConnect(session, ftpserver, INTERNET_INVALID_PORT_NUMBER, user, pass, 1, 0, 0)
    11. ret = FtpPutFile(server, localfile, remotefile, FTP_TRANSFER_TYPE_BINARY, 0)
    12. InternetCloseHandle server
    13. InternetCloseHandle session
    here is as simple as it can get, this is from a working app, i have removed the ftp details as you can see
    i never use c:\ to write files to so as you can see i used app.path in this case, the file is copied to the root folder on the ftp server by default, fname was passed to the sub from the calling sub
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Send Data to FTP without using any OCX ?

    sorry but i dont know why but doesnt work
    i spent a lot of time on it but no error with no file in ftp
    so i will use ocx work fine for me

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Send Data to FTP without using any OCX ?

    whatever works for you is good
    don't know why the api is not working, i have no problem with it
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Send Data to FTP without using any OCX ?

    i dont know m8 ,
    i would be better for me to work with API rather Than an ocx
    but no luck here you my code & test it if it work for you m8

    Thanks
    Attached Files Attached Files

  15. #15
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Send Data to FTP without using any OCX ?

    is your server on the internet or a local server?
    i can only test to server that i have access to
    i changed the server, user, pass and file folder, added ftp module

    ran your form, then opened the file in my browser, showed content of file correctly.

    if you want me to test to your server (if on internet) then pm me, server address, username and pass
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Send Data to FTP without using any OCX ?

    hi m8 ,

    what ftp module did you add to the code ?

  17. #17
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Send Data to FTP without using any OCX ?

    module contains all the api declares and constants for the ftp and internet functions, as posted in above in #4, though there they are private and should go in the general section of the form as i stated with the code
    i have in a module, so i can just add the module to any project
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Send Data to FTP without using any OCX ?

    hi westconn1,

    can you attach your project

  19. #19
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Send Data to FTP without using any OCX ?

    i just opened you uploaded form, added the module i attach here, never saved the project
    Attached Files Attached Files
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Send Data to FTP without using any OCX ?

    hi ,
    i appreciate very much you help westconn1 & i dont know what happend to me but this Ftp dont want to work for me
    here you my Last chance
    i just want you to change only
    ServerName,User,Pass & file name
    and try it

    Thanks m8 !
    Attached Files Attached Files

  21. #21
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Send Data to FTP without using any OCX ?

    zip and reattach
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Send Data to FTP without using any OCX ?

    here you m8

    Thanks
    Attached Files Attached Files

  23. #23
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Send Data to FTP without using any OCX ?

    worked fine to my ftp server
    ph.westconn.com.au/piter.txt
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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