G
Guest
Hi guys please help i'm really stuck.
I'm trying to upload a file from a pcket pc 2003 to a passworded ftp site.
I've tried wininet and its useless so i'm programming my own socket client.
I initialise a connection, and log on over the ftp control socket no problem
but i'm stuck as to how i get the data connection going. Please help, i've
searched for days and can find nothing. Here's what i've got so far having
logged on successfuly:
public sub upload(sFileName as string)
cSocket = CreateDataSocket()
SendCommand("STOR " & "file1.txt")
'read the file into bytes
Dim reaa As System.IO.FileInfo
reaa = New System.IO.FileInfo(sFileName)
Dim oFileStream As System.IO.FileStream = reaa.OpenRead()
Dim lBytes As Long = oFileStream.Length
Dim fileData(lBytes) As Byte
oFileStream.Read(fileData, 0, lBytes)
oFileStream.Close()
cSocket.Send(fileData)
readline()
end sub
Private Function CreateDataSocket() As Socket
s = New Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp)
ep = New IPEndPoint(Dns.Resolve(FRemoteHost).AddressList(0),
FRemotePort)
Try
s.Connect(ep)
Catch ex As Exception
Throw New IOException("Can't connect to remote server")
End Try
Return s
End Function
This produces:
1) after STOR command the file is created on the ftp server and this
repsonse is read from the server(which i think is normal):
"230 User upload logged in.
150 Opening ASCII mode data connection for file1.txt.
"
2) Then right after i send the cSocket.Send(fileData) command i get this
response:
"425 Can't open data connection.
"
Please any suggestions would be appreciated so much. Thanks for your time
Jimbo.
I'm trying to upload a file from a pcket pc 2003 to a passworded ftp site.
I've tried wininet and its useless so i'm programming my own socket client.
I initialise a connection, and log on over the ftp control socket no problem
but i'm stuck as to how i get the data connection going. Please help, i've
searched for days and can find nothing. Here's what i've got so far having
logged on successfuly:
public sub upload(sFileName as string)
cSocket = CreateDataSocket()
SendCommand("STOR " & "file1.txt")
'read the file into bytes
Dim reaa As System.IO.FileInfo
reaa = New System.IO.FileInfo(sFileName)
Dim oFileStream As System.IO.FileStream = reaa.OpenRead()
Dim lBytes As Long = oFileStream.Length
Dim fileData(lBytes) As Byte
oFileStream.Read(fileData, 0, lBytes)
oFileStream.Close()
cSocket.Send(fileData)
readline()
end sub
Private Function CreateDataSocket() As Socket
s = New Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp)
ep = New IPEndPoint(Dns.Resolve(FRemoteHost).AddressList(0),
FRemotePort)
Try
s.Connect(ep)
Catch ex As Exception
Throw New IOException("Can't connect to remote server")
End Try
Return s
End Function
This produces:
1) after STOR command the file is created on the ftp server and this
repsonse is read from the server(which i think is normal):
"230 User upload logged in.
150 Opening ASCII mode data connection for file1.txt.
"
2) Then right after i send the cSocket.Send(fileData) command i get this
response:
"425 Can't open data connection.
"
Please any suggestions would be appreciated so much. Thanks for your time
Jimbo.