Results 1 to 26 of 26

Thread: Connect to FTP Server??

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    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

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    Re: Connect to FTP Server??

    im using 2.0....and how i do that?

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Connect to FTP Server??

    look into the FTPWebRequest class

    Here is the MSDN documentation
    http://msdn2.microsoft.com/en-us/lib...ebrequest.aspx

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    Re: Connect to FTP Server??

    but i cant find there a command to connect....help?

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Connect to FTP Server??

    Quote 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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    Re: Connect to FTP Server??

    i want connect to my FTP server from my website...
    Username,Passwort

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Connect to FTP Server??

    the FTPWebRequest has a credentials property, you can specify credential information there.

  9. #9

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    Re: Connect to FTP Server??

    the property of hte class?

  10. #10
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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:
    1. Using WC As New Net.WebClient
    2.             WC.Credentials = New Net.NetworkCredential("USERID", "PASSWORD")
    3.             WC.DownloadFile("ftp://ftp.somesite.com/somefile.txt", Application.StartupPath & "\somefile.txt")
    4.         End Using

  11. #11

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    Re: Connect to FTP Server??

    ENDIT:
    Thanks for help

  12. #12
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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:
    1. Private Sub HeyHey()
    2. Using WC As New Net.WebClient
    3.             WC.Credentials = New Net.NetworkCredential("USERID", "PASSWORD")
    4.             WC.DownloadFile("ftp://ftp.somesite.com/somefile.txt", Application.StartupPath & "\somefile.txt")
    5.         End Using
    6. End Sub

    Edit: Please dont remove your old text when editing your post like that, it makes me and kleinma look like fools now
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  13. #13
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  14. #14

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    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:
    1. Me.Label4.Text = WC.OpenRead("ADRESS_TO_MY_SERVER/text.txt")
    ERROR


    HELP?

  15. #15
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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:
    1. Dim sr As New IO.StreamReader(WC.OpenRead(ADRESS))
    2.             Label1.Text = sr.ReadToEnd
    3.             sr.Close()
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  16. #16

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    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?

  17. #17
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  18. #18
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Connect to FTP Server??

    Quote 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

  19. #19

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    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:
    1. Imports System
    2. Imports System.Net
    3. Imports System.IO
    4. Public Class Form1
    5.  
    6.  
    7.     Private Sub Form_show()
    8.  
    9.         Using WC As New Net.WebClient
    10.             WC.Credentials = New Net.NetworkCredential("Username", "password")
    11.             Dim sr As New IO.StreamReader(WC.OpenRead("ftp://213.203.202.153/html/test/prog/name.txt"))
    12.             Me.Label4.Text = sr.ReadToEnd
    13.             sr.Close()
    14.         End Using
    15.        
    16.     End Sub
    17.  
    18.  
    19. End Class

  20. #20
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  21. #21

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    Re: Connect to FTP Server??

    eh....what u mean?

  22. #22
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Connect to FTP Server??

    he means that this code will never actually run
    VB Code:
    1. Private Sub Form_show()
    2.  
    3.         Using WC As New Net.WebClient
    4.             WC.Credentials = New Net.NetworkCredential("Username", "password")
    5.             Dim sr As New IO.StreamReader(WC.OpenRead("ftp://213.203.202.153/html/test/prog/name.txt"))
    6.             Me.Label4.Text = sr.ReadToEnd
    7.             sr.Close()
    8.         End Using
    9.        
    10.     End Sub
    unless its being specifically called somewhere...

  23. #23

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    Re: Connect to FTP Server??

    what must i do?

  24. #24
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  25. #25

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    Re: Connect to FTP Server??

    Thanks it Works!

    Great^^
    Last edited by Malle; Dec 23rd, 2006 at 06:42 AM.

  26. #26

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    32

    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
  •  



Click Here to Expand Forum to Full Width