|
-
Dec 21st, 2006, 02:20 PM
#1
Thread Starter
Member
Connect to FTP Server??
Hi!
For my Programm i need to know how i connect to a FTP Server and how i create,copy and change files.
How i do that?
Any help?
Greetz Malle
-
Dec 21st, 2006, 03:23 PM
#2
Re: Connect to FTP Server??
are you using .NET 2.0? it has some built in FTP classes. If you are using .NET 1.1 then you will have to implement your own.
-
Dec 21st, 2006, 03:27 PM
#3
Thread Starter
Member
Re: Connect to FTP Server??
im using 2.0....and how i do that?
-
Dec 21st, 2006, 03:28 PM
#4
Re: Connect to FTP Server??
look into the FTPWebRequest class
Here is the MSDN documentation
http://msdn2.microsoft.com/en-us/lib...ebrequest.aspx
-
Dec 21st, 2006, 04:12 PM
#5
Thread Starter
Member
Re: Connect to FTP Server??
but i cant find there a command to connect....help?
-
Dec 21st, 2006, 04:32 PM
#6
Re: Connect to FTP Server??
 Originally Posted by Malle
but i cant find there a command to connect....help?
What do you mean by connect? As the name File Transfer Protocol implies, you can upload/download files from an FTP server (and of course delete files and stuff)..I dont really see what you mean by connect.
-
Dec 21st, 2006, 04:35 PM
#7
Thread Starter
Member
Re: Connect to FTP Server??
i want connect to my FTP server from my website...
Username,Passwort
-
Dec 21st, 2006, 04:39 PM
#8
Re: Connect to FTP Server??
the FTPWebRequest has a credentials property, you can specify credential information there.
-
Dec 21st, 2006, 04:40 PM
#9
Thread Starter
Member
Re: Connect to FTP Server??
the property of hte class?
-
Dec 21st, 2006, 04:55 PM
#10
Re: Connect to FTP Server??
you might be better off using a webclient. Depends on what you are really looking to do here.
Here is example code to download a file from an FTP site, and specify and ID/Password.
You should be able to use this as a model to figure out the rest
VB Code:
Using WC As New Net.WebClient
WC.Credentials = New Net.NetworkCredential("USERID", "PASSWORD")
WC.DownloadFile("ftp://ftp.somesite.com/somefile.txt", Application.StartupPath & "\somefile.txt")
End Using
-
Dec 21st, 2006, 05:20 PM
#11
Thread Starter
Member
Re: Connect to FTP Server??
-
Dec 21st, 2006, 05:22 PM
#12
Re: Connect to FTP Server??
You have to put it inside a method or subroutine. And also you should always tell what error you are getting 
VB Code:
Private Sub HeyHey()
Using WC As New Net.WebClient
WC.Credentials = New Net.NetworkCredential("USERID", "PASSWORD")
WC.DownloadFile("ftp://ftp.somesite.com/somefile.txt", Application.StartupPath & "\somefile.txt")
End Using
End Sub
Edit: Please dont remove your old text when editing your post like that, it makes me and kleinma look like fools now
-
Dec 21st, 2006, 05:23 PM
#13
Re: Connect to FTP Server??
what errors did it give you?
I sure hope you substituted "USERID", "PASSWORD", and "ftp://ftp.somesite.com/somefile.txt" with REAL values, and not the dummies ones that they are.
-
Dec 21st, 2006, 05:37 PM
#14
Thread Starter
Member
Re: Connect to FTP Server??
ok i want open a text file....the text in it ....its shoul be in Label4....how i do that?
Ive tryed:
VB Code:
Me.Label4.Text = WC.OpenRead("ADRESS_TO_MY_SERVER/text.txt")
ERROR
HELP?
-
Dec 21st, 2006, 05:46 PM
#15
Re: Connect to FTP Server??
I would ask what the error is, as thats a good thing to know..but theres no need for it this time. The OpenRead function doesnt return a string, it returns a stream. You will have to use a streamreader to read it. Like this:
VB Code:
Dim sr As New IO.StreamReader(WC.OpenRead(ADRESS))
Label1.Text = sr.ReadToEnd
sr.Close()
-
Dec 21st, 2006, 05:56 PM
#16
Thread Starter
Member
Re: Connect to FTP Server??
does this doesnt work in debug mode?becuase it show me nothing...only Label4 or is it becuase i can only type the ip?
-
Dec 21st, 2006, 05:59 PM
#17
Re: Connect to FTP Server??
what do you mean by 'shows you nothing?'
Could you show the piece of code you are using, the entire sub.
-
Dec 21st, 2006, 08:00 PM
#18
Re: Connect to FTP Server??
 Originally Posted by Malle
does this doesnt work in debug mode?becuase it show me nothing...only Label4 or is it becuase i can only type the ip?
Sometimes the quality of the answers you get is directly related to the quality of how the question is asked.
You need to be more complete with your questions and give as much information that is relevant to the question as possible.
Otherwise it just looks like you aren't giving any effort and want everything layed out for you, which can turn members off from wanting to help
-
Dec 22nd, 2006, 05:27 AM
#19
Thread Starter
Member
Re: Connect to FTP Server??
sry my english is not the best ^^
I)f i clock on Star Debugging ....Does FTP works in this mode?
I mean : Can i connect to a FTP Server in this mode?
Here is the Code
VB Code:
Imports System
Imports System.Net
Imports System.IO
Public Class Form1
Private Sub Form_show()
Using WC As New Net.WebClient
WC.Credentials = New Net.NetworkCredential("Username", "password")
Dim sr As New IO.StreamReader(WC.OpenRead("ftp://213.203.202.153/html/test/prog/name.txt"))
Me.Label4.Text = sr.ReadToEnd
sr.Close()
End Using
End Sub
End Class
-
Dec 22nd, 2006, 06:15 AM
#20
Re: Connect to FTP Server??
Yeah it works in debug mode.
Are you calling that sub from somewhere? Since I dont see any handle clauses, I suppose its not triggered by the Form_Show event.
-
Dec 22nd, 2006, 02:03 PM
#21
Thread Starter
Member
Re: Connect to FTP Server??
-
Dec 22nd, 2006, 02:04 PM
#22
Re: Connect to FTP Server??
he means that this code will never actually run
VB Code:
Private Sub Form_show()
Using WC As New Net.WebClient
WC.Credentials = New Net.NetworkCredential("Username", "password")
Dim sr As New IO.StreamReader(WC.OpenRead("ftp://213.203.202.153/html/test/prog/name.txt"))
Me.Label4.Text = sr.ReadToEnd
sr.Close()
End Using
End Sub
unless its being specifically called somewhere...
-
Dec 22nd, 2006, 03:33 PM
#23
Thread Starter
Member
Re: Connect to FTP Server??
-
Dec 22nd, 2006, 07:19 PM
#24
Re: Connect to FTP Server??
Call it 
whenever you want to run the code you call the sub by simply writing the name of the sub (and eventually some parameters). For example, double-click your form, this will bring you to the "form load" subroutine, type form_show there and voila, it will run that sub on form load.
-
Dec 23rd, 2006, 04:17 AM
#25
Thread Starter
Member
Re: Connect to FTP Server??
Last edited by Malle; Dec 23rd, 2006 at 06:42 AM.
-
Dec 23rd, 2006, 09:13 AM
#26
Thread Starter
Member
Re: Connect to FTP Server??
but how do i create a file?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|