I am writing an App at the moment and I need to be able to download &
Upload
xml files from an ftp server. Does anyone know how this can be done without
using a third party component.
Try this (may have bugs that need to be worked out which I have not had time
to do)
you can be my guinea pig
Dont forget to change the paths to what you need them to be.
PLEASE let me know the problems you encounter. It will be a big help.
Answers like this can be found with the VB.NET/ADO.NET newsgroup search tool
at
http://www.kjmsolutions.com/newsgrouptool.htm
Module Module1
' Declare the API functions
' The three that you will use are FtpGetFile (for downloading), FtpPutFile
(for uploading), and InternetConnect (to specify the server and login
credentials)
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
' example of how to use the FtpGetFile Function
Sub Download()
Dim INet, INetConn As Integer
Dim RC As Boolean
INet = InternetOpen("FTP Connection", 1, vbNullString, vbNullString,
0)
INetConn = InternetConnect(INet, "
www.myftpserver.com", 21,
"myuser", "mypassword", 1, 0, 0)
RC = FtpPutFile(INetConn, "FTPFolder/MyFiles/MyFile.txt",
"C:\Temp\MyFile.txt", False, 1, 0, 0)
If RC Then MsgBox("Transfer succesfull!")
InternetCloseHandle(INetConn)
InternetCloseHandle(INet)
End Sub
' example of how to use the FtpPutFile Function
Sub Upload()
Dim INet, INetConn As Integer
Dim RC As Boolean
INet = InternetOpen("FTP Connection", 1, vbNullString, vbNullString,
0)
INetConn = InternetConnect(INet, "
www.watyf.com", 21, "myuser",
"mypassword", 1, 0, 0)
RC = FtpPutFile(INetConn, "C:\Temp\MyFile.txt",
"FTPFolder/MyFiles/MyFile.txt", 0, 0)
If RC Then MsgBox("Transfer succesfull!")
InternetCloseHandle(INetConn)
InternetCloseHandle(INet)
End Sub
End Module