Does anyone know how to ftp file from with in a VB App

  • Thread starter Thread starter Neil Rowe
  • Start date Start date
N

Neil Rowe

Hi all


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.

Regards

Neil
 
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
 
* "Neil Rowe said:
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.

It's not supported by the framework.

<http://www.freevbcode.com/ShowCode.Asp?ID=4655>
<http://www.allapi.net/downloads/NetFTP.zip>
<http://www.visualbuilder.com/article/viewarticle.asp?id=1234>
<http://www.abderaware.com/> (FTP component)
<http://www.csharphelp.com/archives/archive9.html>
<http://www.codeproject.com/csharp/FTPDriver1.asp>
....
 
Thanks for that scorpion53061 I will try it out and let you know the
results. Can you module be amended to allow the deletion of the files
locally and on the ftp server.

Regards

Neil
 
Can you module be amended to allow the deletion of the files
locally and on the ftp server.

I would imagine so.

Try to stick with what is there at least initally if you wouln't mind :)
 
Hello Niel

You can do FTP directly through VB.Net. It is a little work, but once done
works nicely.

checkout this link

http://support.microsoft.com/default.aspx?scid=kb;en-us;812404



--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================
Pocket PC Return On Investment Calculator
Free Download http://64.78.34.175/mcsnet/kwickKalk1.aspx
 
Also Neil:

I am working up another class if that fails and this one includes delete,
rename, create directory, delete directory but you will have to email me off
list if you wish to discuss it.

(e-mail address removed)

remove no spam here.
 
Yes I would like to discuss your new class. But you email address does not
work.

Regards

Neil
 
How did the one I sent you work?

My email is (e-mail address removed)

remove nospamhere
 
Back
Top