Hi,
I am trying to connect to a server using the Winsock Control and am in
deep sea.But the problem first...
I need to get the file name of file/files that has been EDI'ed to a
Unix server hosting Oracle.From the client machine I should be able to
access the server,reach a specified directory and get a list of files
residing in the particukar directory that I need to show in a listbox.I
have used a winsock control to connect to the server.Two Winsock controls
actually,one acting as a client ,the other the server.The client is used
mainly for handshaking purpose while the server collects data after the
binary mode transfer is opened.
The problem is that I do get a connection to the server and it accepts
the IP,username and password but severes connection whenever I send the
directory listing command.It gives me a error code 425.The code that I am
using is as follows:
Private Sub cmdConnect_Click()
'Establish connection
Call EstablishConnection(wsckClient, True, UNIXHOSTNAME)
'disable controls
'Call DisableControls
End Sub
'This procedure would either establish connection with the remote FTP
server
'or it would ask open a socket and ask it to listen to request
'sent by the FTP server
Private Sub EstablishConnection(Wsck As Winsock, blnDefaultPort As
Boolean, Optional strHostName As String)
On Error GoTo label
'if the socket is not closed , close it
If Wsck.State <> sckClosed Then Wsck.Close
If blnDefaultPort Then
' open socket to remote host's FTP port
Wsck.LocalPort = 21
Wsck.Connect strHostName(e.g 192.50.200.70), intFreePort(e.g
15000)
Wsck.Connect
End If
Exit Sub
label:
MsgBox Err.Number & Err.Description
wsckClient.Close
End Sub
Private Sub wsckClient_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
'read the response sent by server in to the strData variable
wsckClient.GetData strData
Debug.Print strData
'call the SendDataToServer procedure to send data back to server
'MsgBox (strData)
Call SendDataToServer(Left(strData, 3))
End Sub
'This procedure is to send request to the FTP server
'according to the response sent by the FTP server
Private Sub SendDataToServer(intResCode As Integer)
Dim strMsg As String, strIPAddress As String, strSend As String
On Error GoTo errhandler
Select Case intResCode
Case RES_ERROR
strMsg = "There was an error while opening the
connection" & Chr(13)
strMsg = strMsg & "Do you want to reconnect ?"
Timer1.Enabled = False
'if an error occurs while opening the data port
'prompt the user for reestablishing the connection
If MsgBox(strMsg, vbYesNo + vbQuestion +
vbDefaultButton1, "Error While Connecting") = vbYes Then
Call EstablishConnection(wsckClient, True,
"192.50.200.70")
Else
wsckClient.SendData "Quit"
wsckClient.Close
End If
pgrStatus.Value = 0
'---------------------------------------------------------------------------------------------------------------
Case RES_USER
'after opening the socket to the FTP server
'send in the login user name
wsckClient.SendData "USER " & UNIXUSERID & vbCrLf
'Update the progress bar
Call UpdateProgress
'---------------------------------------------------------------------------------------------------------------
Case RES_PASSWORD
'after sending in the user name send the password
wsckClient.SendData "PASS " & UNIXPWD & vbCrLf
'Update the progress bar
Call UpdateProgress
'---------------------------------------------------------------------------------------------------------------
Case RES_CD
'set the current directory on the FTP server
wsckClient.SendData "CWD " & UNIXHOSTDIR & vbCrLf
'Update the progress bar
Call UpdateProgress
'---------------------------------------------------------------------------------------------------------------
Case RES_PWD
'print the current directory on the FTP server
wsckClient.SendData "PWD" & vbCrLf
'Update the progress bar
Call UpdateProgress
'---------------------------------------------------------------------------------------------------------------
Case RES_CURDIR
strIPAddress = CStr(wsckClient.LocalIP)
strSend = "PORT " & Replace(strIPAddress, ".",
",")
strSend = strSend & "," & intFTPPort \ 256 & "," &
intFTPPort
strSend = strSend & vbCrLf
'send in the port and ip address details of the
socket
'to where the data is to be sent
wsckClient.SendData strSend
'Update the progress bar
Call UpdateProgress
'---------------------------------------------------------------------------------------------------------------
Case RES_PORTCMDSUCCESS------->******(IT is here that the problem
occurs)
'list the data to be sent to the client
'wsckClient.SendData "LIST" & vbCrLf
wsckClient.SendData "LIST" '& vbCrLf
'Update the progress bar
Call UpdateProgress
'---------------------------------------------------------------------------------------------------------------
Case RES_OPENBINMODE
Call EstablishConnection(wsckServer, False,
strRemHost)
'Update the progress bar
Call UpdateProgress
Timer1.Enabled = True
'---------------------------------------------------------------------------------------------------------------
Case RES_TRANSFERCOMPLETE
wsckClient.SendData "QUIT"
'---------------------------------------------------------------------------------------------------------------
End Select
Exit Sub
errhandler:
'wsckClient.SendData "Quit"
wsckClient.Close
End Sub
WHenever control passes to --Case RES_PORTCMDSUCCESS-- the error occurs
and connection is closed.
The Case codes are basically FTP Server Response constants which I have
declared in the Declarations section.I am including the list below.
Private Const RES_ERROR = 425
Private Const RES_USER = 220
Private Const RES_PASSWORD = 331
Private Const RES_CD = 230
Private Const RES_PWD = 250
Private Const RES_CURDIR = 257
Private Const RES_PORTCMDSUCCESS = 200
Private Const RES_OPENBINMODE = 150
Private Const RES_TRANSFERCOMPLETE = 226
I really should thank you for your patience.Any help is welcome.
Thanks in advance,
Indranil