I need to implement FTP in an application and<br>
would like some code samples that I could study. Does<br>
anyone know of some code samples using ITC in VB?<br>
Thanks.
Perhaps these two functions could give you a start, uses the internet transfer control that comes with VB. Bit mickey mouse, should be more paramaterised - but does have the major thing about the itc. Each time you ask it to do something - wait for it to finish.<br>
<br>
Regards<br>
<br>
Mike<br>
<br>
Public Sub WaitForIC(ic As Inet)<br>
<br>
' waits for an internet transfer control, ic, <br>
' to finish what it's doing - if anything<br>
<br>
With ic<br>
Do<br>
DoEvents<br>
Loop While .StillExecuting<br>
End With<br>
<br>
End Sub<br>
<br>
Public Function XferFile( _<br>
itc as Inet, _<br>
fname As String _<br>
) As Boolean<br>
<br>
On Error GoTo XferFile_ErrHandler<br>
<br>
' Transfers a file to a target machine.<br>
<br>
Dim lsHostName As String<br>
Dim lsUserName As String<br>
Dim lsPassword As String<br>
Dim lsTmpDirName As String<br>
Dim lsTargetdir As String<br>
<br>
Dim lsCDcmd As String<br>
Dim lsPUTcmd As String<br>
Dim lsMsg As String<br>
<br>
' XferFile = True: Exit Function<br>
<br>
If (fname = vbNullString) Then<br>
XferFile = False<br>
Exit Function<br>
End If<br>
<br>
Call WaitForIC(itc)<br>
<br>
lsHostName = "some.computer.com"<br>
lsUserName = "valid_user_name"<br>
lsPassword = "valid_password"<br>
lsTargetdir = "dir_on_lsHostName"<br>
<br>
' lsPUTcmd = "PUT " & lsTmpDirName _<br>
& fname & " " & lsTargetdir & fname _<br>
& " PUT " & lsTmpDirName & fname & " " _<br>
& lsTargetdir & "tmpthing.txt"<br>
<br>
itc.AccessType = icDirect<br>
Call WaitForIC(itc)<br>
<br>
itc.Protocol = icFTP<br>
Call WaitForIC(itc)<br>
<br>
itc.URL = "ftp://" & lsHostName<br>
Call WaitForIC(itc)<br>
<br>
itc.UserName = lsUserName<br>
Call WaitForIC(itc)<br>
<br>
itc.Password = lsPassword<br>
Call WaitForIC(itc)<br>
<br>
itc.Execute itc.URL, lsPUTcmd<br>
Call WaitForIC(itc)<br>
<br>
XferFile = True<br>
<br>
Exit Function<br>
<br>
XferFile_ErrHandler:<br>
<br>
lsMsg = "An Error has occurred whilst transferring" _<br>
& " a file to the Target Computer." _<br>
& " Check the Status display for error" _<br>
& " messages, you may have to use the scroll" _<br>
& " bar to see all of the messages." _<br>
& vbCrLf & vbCrLf<br>
<br>
If mLastInetResponseCode <> 0 Then<br>
lsMsg = lsMsg _<br>
& " The last recorded response from the" _<br>
& " Target Computer was:" & vbCrLf & vbCrLf _<br>
& mLastInetResponseCode & ": " _<br>
& mLastInetResponseInfo _<br>
& vbCrLf & vbCrLf<br>
End If<br>
<br>
txtConvError.Text = lsMsg _<br>
& vbCrLf & vbCrLf & txtConvError.Text<br>
<br>
XferFile = False<br>
Exit Function<br>
<br>
End Function<br>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.