Very basically FTP-Client
Connects with a FTP-Server and transfers a file to it. I use it to transfer my IP to my HP every time I connect to the net
AI
สรุปโดย AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
ซอร์สโค้ด
Dim x1 As Long Dim x2 As Long Dim last As String Private Sub Command1_Click() Winsock2.RemoteHost = "" 'Enter Server here Winsock2.RemotePort = 21 ' Usually the port is 21, but if it's different, enter it here Winsock2.Connect Do Until Winsock2.State = sckConnected ' Wait until connected DoEvents Debug.Print Winsock2.State Loop Winsock2.SendData "USER " & vbCrLf 'Enter username behind USER last = "" Do Until last <> "" 'Wait until server responds DoEvents Loop Winsock2.SendData "PASS " & vbCrLf 'Enter password behind PASS last = "" Do Until last <> "" 'Wait until server responds DoEvents Loop Randomize x1 = Int(10 * Rnd + 1) ' Find two random numbers to specify port the server connects to Randomize x2 = Int(41 * Rnd + 10) Dim ip As String ip = Winsock2.LocalIP Do Until InStr(ip, ".") = 0 ' replace every "." in IP with a "," ip = Mid(ip, 1, InStr(ip, ".") - 1) & "," & Mid(ip, InStr(ip, ".") + 1) Loop Winsock2.SendData "PORT " & ip & "," & Trim(Str(x1)) & "," & Trim(Str(x2)) & vbCrLf 'Tell the server with which IP he has to connect and with which port last = "" Do Until last <> "" 'Wait until server responds DoEvents Loop Winsock1.Close Winsock1.LocalPort = x1 * 256 Or x2 ' Set port of second winsock-control to the port the server will connect to ' x1 is the most-significant byte of the port number, x1 is the least significant byte. To find the port, you have to move every bit 8 places to the right (or multiply with 256). Then compare every bit with the bits of x2, using OR Winsock1.Listen 'Listen for the FTP-Server to connect Winsock2.SendData "STOR ich.html" & vbCrLf 'Store a file, with RETR you can get a file, with LIST you get a list of all file on the server, all this information is sent through the data-connection (to change directory use CWD) Do Until Winsock1.State = sckConnected 'Wait until the FTP-Server connects DoEvents Loop Pause 1 'wait a little bit, because the server needs a moment (don't know how, but it only works so) Winsock1.SendData "TEST" 'Send some data, the FTP-Server will store it in the file. Send only ASCII data, if you send Binary you have to tell it the server before, use TYPE to do this Pause 1 Winsock1.Close ' Close data-connection Pause 1 Winsock2.Close 'You don't have to close the connection here, you also can transfer another file End Sub Public Sub Pause(Seconds) Dim Zeit As Long Zeit = Timer Do DoEvents Loop Until Zeit + Seconds <= Timer End Sub Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long) Winsock1.Close Winsock1.Accept requestID End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim data As String Winsock1.GetData data Debug.Print data Winsock1.Close ' You have to close the connection after the Server had send you data, he will establish it again, when he sends more Winsock1.Listen End Sub Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long) Dim data As String Winsock2.GetData data Debug.Print data last = data 'Store data End Sub Upload
ความคิดเห็นดั้งเดิม (3)
กู้คืนจาก Wayback Machine