home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / HelpACoder45984132002.psc / Ftp_Upload.bas < prev    next >
Encoding:
BASIC Source File  |  2002-01-04  |  3.1 KB  |  81 lines

  1. Attribute VB_Name = "Ftp_Upload"
  2. 'Used for download
  3.     'used for downloading files
  4.     Public Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
  5.     '
  6. 'Needed to connect
  7.     Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
  8.     '
  9. 'Connect
  10.     Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
  11.     '
  12. 'Close connection
  13.     Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
  14.     '
  15. 'Place a file
  16.     Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
  17.     '
  18.  
  19. 'Jest a few constants
  20.     Public Const INVALID_PORT = 0
  21.     Public Const OPEN_TYPE = 1
  22.     Public Const SERVICE_FTP = 1
  23.     Public Const FLAG_PASSIVE = &H8000000
  24.     Const FTP_BINARY = &H2
  25. Public Sub MakeFile(NewText As String)
  26. Dim Cfile As String
  27. Dim Cfile2 As String
  28. 'open file to Cfile
  29.     Cfile = Form1.Inet.OpenURL("www.jemisp.com/visualcode/nrequest.rqst", icString)
  30.     Cfile2 = Form1.Inet.OpenURL("www.jemisp.com/visualcode/want.rsd", icString)
  31.     '
  32. 'add to file
  33.     Cfile = Cfile & vbCrLf & NewText
  34.     Cfile2 = Cfile2 & vbCrLf & NewText
  35.     '
  36. 'save files
  37.     Open "C:\tmp1.trsh" For Output As #1
  38.     Print #1, Cfile
  39.     Close #1
  40.     Open "C:\tmp2.trsh" For Output As #1
  41.     Print #1, Cfile2
  42.     Close #1
  43.     '
  44. 'Make it upload
  45.     PutFile
  46.     '
  47. End Sub
  48.  
  49.  
  50. Public Sub PutFile()
  51. 'For Your Information
  52.     'This is not broken it will not work
  53.     'because you need a password the reason
  54.     'I still left the code is so you can learn
  55.     'from it though you need a site and and
  56.     'A correct password.
  57.     '
  58. 'Connet to ftp server
  59.     Ftp_hOpen = InternetOpen("vb wininet", INVALID_PORT, vbNullString, vbNullString, 0)
  60.     Ftp_Hconnection = InternetConnect(Ftp_hOpen, "www.jemisp.com", INVALID_PORT, "Visualcode", "PASSWORD", SERVICE_FTP, FLAG_PASSIVE, 0)
  61.     '
  62. 'Tell them if it errors and exit sub
  63.     If Ftp_Hconnection = 0 Then MsgBox "Could not connect check and make sure your connected to the internet", vbCritical, "Error Connecting": Exit Sub
  64.     '
  65. 'Add file to site
  66.     'this is here just so i can see whats added
  67.     'just for filtering
  68.     FtpPutFile Ftp_Hconnection, "C:\tmp1.trsh", "nrequest.rqst", FTP_BINARY, 0
  69.     'this adds it to the file
  70.     FtpPutFile Ftp_Hconnection, "C:\tmp2.trsh", "want.rsd", FTP_BINARY, 0
  71.     '
  72. 'Close Connection
  73.     InternetCloseHandle Ftp_Hconnection
  74.     '
  75. 'delete files
  76.     Kill "C:\tmp1.trsh"
  77.     Kill "C:\tmp2.trsh"
  78. End Sub
  79.  
  80.  
  81.