?
Solved

What is the difference between Winsock and wininet control for FTP.

Posted on 2005-05-03
7
Medium Priority
?
773 Views
Last Modified: 2013-11-13
What are the advantage and disadvantages for using Winsock and wininet for ftp control.
0
Comment
Question by:Bharat Guru
4 Comments
 

Expert Comment

by:STStheBest
ID: 13919069
To connect PCs with each other you can better use the winsock control, to download files you can better use the wininet control.

But if you specify your purpose, I can advise you better which to use.
0
 

Author Comment

by:Bharat Guru
ID: 13919411
I want to write a FTp component for FTping a files to some destination server. I want to know if for any reason if connection failed between two servers can i continue ftping files where it left off.  Is it possible to do that in either component. And I want to know which controls are better for error traping. And waht are the main differences between two controls.
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 100 total points
ID: 13920035
If by Wininet you mean the APIs as used by this sample:
SAMPLE: VBFTP.EXE: Implementing FTP Using WinInet API from VB
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q175179

Then the primary difference is that WinInet handles all the protocol stuff for you.  If you try to create an FTP control using the Winsock control, you have to understand the FTP protocol--all the commands that are sent, and the possible responses.

If you mean the Inet control, this is an even simpler control that operates at an even higher level.  I've seen a lot of people that have problems using it for FTP however.  In my experience, using the API gives you more control over what happens when things go wrong.

>I want to know if for any reason if connection failed between two servers can i continue ftping files where it left off.
The best way to do this is to keep a list of the files, and remove them from the list as they are successfully uploaded.  Then if you  encounter problems save the list somewhere so that you can reload it when you attempt again.

0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 13921929
'Copy and Paste the following code in the Form_Declerations
'=================================

Option Explicit
'FTP declares start
Private Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
Private Const FTP_TRANSFER_TYPE_ASCII = &H1
Private Const FTP_TRANSFER_TYPE_BINARY = &H2
Private Const INTERNET_DEFAULT_FTP_PORT = 21
Private Const INTERNET_SERVICE_FTP = 1
Private Const INTERNET_FLAG_PASSIVE = &H8000000
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const INTERNET_OPEN_TYPE_PROXY = 3
Private Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4
Private Const MAX_PATH = 260
Private Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    nFileSizeHigh As Long
    nFileSizeLow As Long
    dwReserved0 As Long
    dwReserved1 As Long
    cFileName As String * MAX_PATH
    cAlternate As String * 14
End Type

Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet 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 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 FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String, lpdwCurrentDirectory As Long) As Long
Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpRemoveDirectory Lib "wininet.dll" Alias "FtpRemoveDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" (ByVal hFtpSession As Long, ByVal lpszExisting As String, ByVal lpszNew As String) As Boolean
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
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
Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (lpdwError As Long, ByVal lpszBuffer As String, lpdwBufferLength As Long) As Boolean
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
Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
Private Const PassiveConnection As Boolean = True
'Ftp Declares end
'Additonal
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'Timer related
Private Const modMinutes = 1 'set in minutes when to execute command
Dim currentTick As Integer
Sub Upload_WANIP(FS As String, UN As String, P As String, F As String, FilePath As String, UploadedFilename As String)
'FS=FTP SERVER
'UN=USERNAME
'P=PASSWORD
'F=FOLDERNAME TO CREATE ON FTP
'FilePath=Location of file on your pc to upload
'UploadedFilename=The filename of the uploaded file

DoEvents
Dim hConnection As Long, hOpen As Long, sOrgPath  As String
    hOpen = InternetOpen("FTP", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
    Sleep 500
    DoEvents
    hConnection = InternetConnect(hOpen, FS, INTERNET_DEFAULT_FTP_PORT, UN, P, INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
    Sleep 500
    DoEvents
    sOrgPath = String(MAX_PATH, 0)
    FtpGetCurrentDirectory hConnection, sOrgPath, Len(sOrgPath)
    Sleep 500
    DoEvents
    FtpCreateDirectory hConnection, F
   Sleep 500
   DoEvents
    FtpSetCurrentDirectory hConnection, F
  Sleep 500
   DoEvents
    FtpPutFile hConnection, FilePath, UploadedFilename, FTP_TRANSFER_TYPE_ASCII, 0
   Sleep 500
   DoEvents
    FtpSetCurrentDirectory hConnection, sOrgPath
     Sleep 500
   DoEvents
    InternetCloseHandle hConnection
     Sleep 500
   DoEvents
    InternetCloseHandle hOpen
 Sleep 500
   DoEvents
End Sub


'====================================================
'ADD 1 COMMAND BUTTON
'PUT THIS CODE INSIDE THE COMMAND BUTTON

Call Upload_WANIP("ftp.server.com", "username", "password", "WANIP", "c:\wanip.txt", "wanip.txt")
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question