Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you open an FTP Session?

Status
Not open for further replies.

faust13

Programmer
Aug 7, 2001
176
US
How do you open an FTP Session?

I've looked everywhere, I can't find it anywhere in the documentation.

I used to use the Inet object, but this doesn't exist in VB .Net. What do we use now?

Any suggestions? --------------------------------------
Is George Lucas Kidding...
Noise Core: 7.62
 
Hello,
I have not tried it but i assume that is the same as sending TCP messages.
See the TCPClient (on the MSDN help) Class for an example

ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemnetsocketstcpclientclasstopic.htm

Hope that helps "The Camel will walk the desert of programming once again ..."

Camel
 
Camel thanks for the pointer, but I'm still having problems. The TCPClient does seem to opent the session, but I'm not able to interact with the server, or get the 220 response. Instead I get an error stating the connection was forcibly closed by the server.

I can't be the first one to write an FTP client in VB .Net, but I can't find any information on this anywhere. I have really, really looked.

Here's my code:

Dim hostName As String = "myIPAddress"
Dim portNum As Integer = 80

'Open the connection with address and port
Dim client As New System.Net.Sockets.TcpClient(hostName, portNum)

'Create a new stream
Dim ns As System.Net.Sockets.NetworkStream = client.GetStream()

'Translate the stream
Dim bytes(1024) As Byte
Dim bytesRead As Integer = ns.Read(bytes, 0, bytes.Length)

'Output stream
Label16.Text = System.Text.Encoding.ASCII.GetString(bytes, 0, bytesRead)

'Close the connection
client.Close() --------------------------------------
Is George Lucas Kidding...
Noise Core: 7.62
 
Hi,

I am also looking for a solution to open an ftp session and identify and download any files that exist.

Could you please let me know in this thread if you find, or have found a solution to this problem. I have also spent many hours on the Web trying to find an FTP Control for vb.net. I have found many for vb 6.

Many Thanks

Steve
 
I got it work a little, I get the 220 when I open the connection, but it seems like the writing is failing (when authenicating). I have a couple msgBoxes to track the process, but they come up empty after the first one with the 220 code.

Here's my code:

Private Sub uploadReports()
Dim hostName As String = "myIP"
Dim portNum As Integer = 21

Dim client As New System.Net.Sockets.TcpClient(hostName, portNum)

Dim ns As System.Net.Sockets.NetworkStream = client.GetStream()

Dim comRead = New StreamReader(ns)

'I get a 220 here as expected
MsgBox(comRead.readLine())

Dim command As String = "USER user"

MsgBox("Writing to stream")

ns.Write(System.Text.Encoding.ASCII.GetBytes(command + "\n"), 0, command.Length + 1)

'This displays as an empty msgbox
MsgBox(comRead.ReadLine())

command = "PASS pass"

MsgBox("Writing to stream")

ns.Write(System.Text.Encoding.ASCII.GetBytes(command + "\n"), 0, command.Length + 1)

'This displays as an empty msgbox
MsgBox(comRead.ReadLine())

MsgBox("Closing")
client.Close()
End Sub

Any insight is welcome. --------------------------------------
Is George Lucas Kidding...
Noise Core: 7.62
 
Have you looked into Pluggable Protocols?

If not, check it out and let me know how it works.
 
WillBarns,

I've read a little about them, but the documentation is not clear on how to use them for FTP. Do you have any more resource about them (other than what's on MSDN)?

Thanks --------------------------------------
Is George Lucas Kidding...
Noise Core: 7.62
 
I'm with you -- sounds promising but I want a nice FTP sample program using pluggable protocols to make it clear. I'll look around and let you know if I find something.
 
WillBarns,

Thanks for the link, I will check it out when I have a little time (Tuesday).

Here's a link to Microsoft's Newsgroup for VB .Net, where the actual .Net Dev Team responds to this issue.
I didn't find their links terribly useful, but check it out. Every bit of help, helps, right?

I'll keep on this until there is a clear solution.

Thanks again. --------------------------------------
Is George Lucas Kidding...
Noise Core: 7.62
 
Thanks for the link.

Do you still have your INet solution?

What happens when you run it through the VB.NET conversion process?
 
Yes, I have the Inet solution, when I try to import it, VB .Net's wizard reports there are missing referred components and suggests reinstalling VB 6 and including them. I have no idea what is talking about, I still have the .dll on my system. --------------------------------------
Is George Lucas Kidding...
Noise Core: 7.62
 
hi faust13,

you are on the right track, but the command + "\n" part doesn't work (the server doesn't recognise that the command has been terminated). i changed it by appending a vbcrlf at the end of each command before converting it to a byte array and this seems to work. here is the code.

Private Sub ftp(ByVal host As String, Optional ByVal port As Integer = 21)

Dim client As New System.Net.Sockets.TcpClient(host, port)

Dim ns As System.Net.Sockets.NetworkStream = client.GetStream()

Dim comRead = New StreamReader(ns)

'I get a 220 here as expected
MsgBox(comRead.readLine())

Dim command As String = "USER user" & vbCrLf

MessageBox.Show("Writing to stream")

ns.Write(System.Text.Encoding.ASCII.GetBytes(command & vbCrLf), 0, command.Length)

'This displays as an empty msgbox
MessageBox.Show(comRead.ReadLine())

command = "PASS password" & vbCrLf

MessageBox.Show("Writing to stream")

ns.Write(System.Text.Encoding.ASCII.GetBytes(command & vbCrLf), 0, command.Length)

'This displays as an empty msgbox
MsgBox(comRead.ReadLine())

MsgBox("Closing")
client.Close()

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top