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
Printable View
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
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.
im using 2.0....and how i do that?
look into the FTPWebRequest class
Here is the MSDN documentation
http://msdn2.microsoft.com/en-us/lib...ebrequest.aspx
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.Quote:
Originally Posted by Malle
i want connect to my FTP server from my website...
Username,Passwort
the FTPWebRequest has a credentials property, you can specify credential information there.
the property of hte class?
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
ENDIT:
Thanks for help
You have to put it inside a method or subroutine. And also you should always tell what error you are getting :thumb:
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 ;)
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.
ok i want open a text file....the text in it ....its shoul be in Label4....how i do that?
Ive tryed:
ERRORVB Code:
Me.Label4.Text = WC.OpenRead("ADRESS_TO_MY_SERVER/text.txt")
HELP?
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()
does this doesnt work in debug mode?becuase it show me nothing...only Label4 or is it becuase i can only type the ip?
what do you mean by 'shows you nothing?'
Could you show the piece of code you are using, the entire sub.
Sometimes the quality of the answers you get is directly related to the quality of how the question is asked.Quote:
Originally Posted by Malle
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 :wave:
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
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.
eh....what u mean?
he means that this code will never actually run
unless its being specifically called somewhere...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
what must i do?
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.
Thanks it Works!
Great^^
but how do i create a file?