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 from VB.Net 2

Status
Not open for further replies.

Fig000

Programmer
Jun 13, 2001
12
0
0
US
Hi,

I would like to ftp a file from inside a vb.net program. I've looked on the web but have seen mostly reccommendations for third party components. I've sent e-mails from vb.net (in an asp.net applicaitons) so I figure there should be something similar (an ftp object for istance) that is already part of vb.net.

Does anyone have any suggestions/code.

Neil
 
Hi,
you can use the wininet API:

--------------------------------------------------
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal HINet As Integer) As Integer
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Integer, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Integer) As Integer
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Integer, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Integer, ByVal lFlags As Integer, ByVal lContext As Integer) As Integer
Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hFtpSession As Integer, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttributes As Integer, ByVal dwFlags As Integer, ByVal dwContext As Integer) As Boolean
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hFtpSession As Integer, ByVal lpszLocalFile As String, ByVal lpszRemoteFile As String, ByVal dwFlags As Integer, ByVal dwContext As Integer) As Boolean
...
Dim INet, INetConn As integer
Dim RC As Boolean
INet = InternetOpen("MyFTP Control", 1, vbNullString, vbNullString, 0)
INetConn = InternetConnect(INet, " 0, "yourlogin", "yourpassword", 1, 0, 0)
RC = FtpGetFile(INetConn, "/folder/subfolder/name.ext", "c:\tmp\downloaded.ext", true, 1, 0, 0)
If RC Then MessageBox.show( "Transfer succesfull!")
InternetCloseHandle INetConn
InternetCloseHandle INet
------------------------------------------------

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Everyone has given me excellent help with the FTP problem. However I wonder why people tend to shy away from the simple solutions such as hte one the sunaj posted. I used this and was on my way in a few minutes.
I understand this is not a full gui solution but is perfect for ftping something from inside a program.

Thanks sunaj. You saved me days.

Neil
 
Download samples 101 from microsoft. There is a sample to send data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top