Winsock - FTP best practice
Posted on 2005-05-17
I'm in the middle of writing some code to allow a user to FTP to a web server
The server uses Passive FTP and so I have two winsock controls, one to handle the commands and one to handle the
The code to log on to the server works fine and I have even worked out how to deal with parsing the IP address in
after I have sent the FTP command PASV.
The senddata commands and the server responses are all handled with a case statement unlike the code below.
I don't want any links to download other FTP programs as I am looking to write this project as a bit of a learning curve.
I have a number of questions hence the 500 points.
Public Sub SendData()
FileName = "c:\logo.png" - Hardcoded for the time being
txt_FileSize = FileLen(FileName)
Dim str() As Byte
Open FileName For Binary As #1
Get #1, , str
Winsock1.SendData "STOR logo.png" & vbCrLf - Hardcoded for the time being
1) What is the best way to upload a file - The code above works but I have read that you should break the upload down into chunks. How do I do this and why should I ?
2) When the code above starts uploading I get the server response 125 Data Connection already Open back from Winsock1, which is used to send the commands but nothing to tell me when the transfer is complete i.e. FTP Code 226 - Why ?
3) I get no server response on winsock2 in terms of FTP response, but I can track the number of bytes sent etc - Why ?
Public Sub DownloadData()
FileName = "c:\logo.png"
Open FileName For Binary Access Write As #1
Winsock1.SendData "RETR logo.png" & vbCrLf
Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Dim str() As Byte
Put #1, , str
4) The code above works to download a file - This really needs to be written properly - Any Suggestions ?? - I do get 226 Transfer Complete when it has finished.
Thanks in Advance