By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 965 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Nov 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
> 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
Nov 20 '05 #2

P: n/a
* "Neil Rowe" <ne*******@blueyonder.co.uk> scripsit:
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>
....

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
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
Nov 20 '05 #4

P: n/a
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 :)
Nov 20 '05 #5

P: n/a
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...en-us%3B812404

--
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

"Neil Rowe" <ne*******@blueyonder.co.uk> wrote in message
news:e2**************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #6

P: n/a
> >
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.


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.

kj*@nospamherecharter.net

remove no spam here.
Nov 20 '05 #7

P: n/a
Yes I would like to discuss your new class. But you email address does not
work.

Regards

Neil

"scorpion53061" <Its the end of the world as we know it@here.com> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...

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.


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.

kj*@nospamherecharter.net

remove no spam here.

Nov 20 '05 #8

P: n/a
How did the one I sent you work?

My email is kj*@nospamherecharter.net

remove nospamhere

"Neil Rowe" <ne*******@blueyonder.co.uk> wrote in message
news:e4**************@TK2MSFTNGP11.phx.gbl...
Yes I would like to discuss your new class. But you email address does not
work.

Regards

Neil

"scorpion53061" <Its the end of the world as we know it@here.com> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
>
> 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.


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.

kj*@nospamherecharter.net

remove no spam here.


Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.