Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP'ing with VB

Status
Not open for further replies.

sweetleaf

Programmer
Jan 16, 2001
439
0
0
CA
Hi there,

I have an exe that i want to be able to simply ftp a file from.

Is there a simple way to do this, or can this not happen inside of VB ?

Thanks!
 
Have you looked in the Inet Control? If that doesn't work, then you do have access to a number of API's which can perform most FTP functions. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
The below code will get you started using the Inet Control.
it will open an FTP and get a list of files. To get the file do an inet1.Execute.

Public Function FTPGET(Server As String, UID As String, PW As String, FromDIR As String, ToDIR As String, ClientFormat As String)

Dim strTmp as String
Dim strFileList as String

'add trailing \ if needed.
If Right(ToDIR, 1) <> &quot;\&quot; Then ToDIR = ToDIR & &quot;\&quot;

'Open FTP connection
Inet1.Cancel
Inet1.AccessType = icUseDefault
Inet1.Protocol = icFTP
Inet1.RemotePort = 21
Inet1.URL = &quot;ftp://&quot; & Server
Inet1.UserName = UID
Inet1.Password = PW


Inet1.Execute , &quot;DIR &quot; & FromDIR & &quot;*.*&quot;

While Inet1.StillExecuting = True
DoEvents
Wend


'Get a list of files on the FTP
strTmp = Inet1.GetChunk(1024)
Do While Len(strTmp) > 0
DoEvents
strFileList = strFileList & strTmp
strTmp = Inet1.GetChunk(1024)
Loop


 
Thanks guys!

Is inet1 control something i should be able to see and select in project references?

DirectDrive, is the above to be in an exe or activex dll?

Thanks!
 
MSINET.OCX = the inet control

The function is from an exe with the inet control added to the form.
 
Here is what we did in this situation. We pulled all of the variables from an external text file so that we didn't half to rewrite code when the ftp requirements of vendors change.
Also alot of this code is from outside sources, I will try and find the original developers name so that he can get credit on this forum. This is an extremely basic example. It does work well for us.

Code:
Public Sub SendFTPOrder()
  InetFTP.RemoteHost = &quot;&quot;
  InetFTP.Username = &quot;&quot;
  InetFTP.Password = &quot;&quot;
  InetFTP.Url = &quot;&quot;
  
  'Write the three required FTP Login variables to the registry
'  SaveSetting &quot;FTPuploader&quot;, &quot;FTP&quot;, &quot;hostname&quot;, sTempVendor.Url
'  SaveSetting &quot;FTPuploader&quot;, &quot;FTP&quot;, &quot;username&quot;, sTempVendor.Username
'  SaveSetting &quot;FTPuploader&quot;, &quot;FTP&quot;, &quot;password&quot;, sTempVendor.Password
  
  InetFTP.RemoteHost = Url
  InetFTP.Username = Username
  InetFTP.Password = Password
        
        Screen.MousePointer = vbHourglass
        
        frmOrderAdmin.InetFTP.Execute , &quot;PUT &quot;&quot;&quot; & FilePath & &quot;&quot;&quot; &quot; & FileName
        
        
        ' This allows me to wait until the file is done transfering
        Do Until frmOrderAdmin.InetFTP.StillExecuting = 0
            DoEvents
        Loop

    InetFTP.Execute , &quot;Quit&quot;
    Screen.MousePointer = Default
    MsgBox &quot;Message sent via FTP successfully.&quot;
    bComplete = True
    Kill (sTempVendor.FilePath)
    Exit Sub
ErrorHandler:
If (Err.Number <> 0) Then
  MsgBox &quot;Error: &quot; & Err.Description, vbExclamation, &quot;Error Saving File.&quot;
End If
Screen.MousePointer = Default
End Function

Thanks,

bnye

PS The INET ocx is a little tiny globe with a computer in front of it slightly off center.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top