ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¦p¦ó¥ÎVBA ¤W¶ÇÀɮצÜFTP?

[µo°Ý] ¦p¦ó¥ÎVBA ¤W¶ÇÀɮצÜFTP?

¦U¦ì¤j¤j¦n,¤p§Ì·Q¦V¤j®a½Ð±Ð¤W¶Çªº¤èªk
¦³§ä¤F½d¨ÒªºCODE³£µLªk¥¿±`°õ¦æ,¤£¾å±o¬O­þÃ䪺¿ù»~,ÁٽФj¤j­Ì«ü±Ð¤@¤U
¦³²q´ú¬O§ÚªºFTP¸ô®|¿é¤J¿ù»~
°²³]§ÚªºFTP¦ì¸m¬Oftp://test.com
§Ú­n©ñ¨ì¸Ó¦ì¸mªº¤U­±
¨º½d¨ÒªºhostFile ­n«ç»ò¿é¤J?hostFile ="ftp://test.com/a.csv" ¬O³o¼Ë¶Ü?
  1. Private Declare Function InternetOpen _
  2.    Lib "wininet.dll" _
  3.      Alias "InternetOpenA" _
  4.        (ByVal sAgent As String, _
  5.         ByVal lAccessType As Long, _
  6.         ByVal sProxyName As String, _
  7.         ByVal sProxyBypass As String, _
  8.         ByVal lFlags As Long) As Long

  9. 'Connect to the network
  10. Private Declare Function InternetConnect _
  11.    Lib "wininet.dll" _
  12.      Alias "InternetConnectA" _
  13.        (ByVal hInternetSession As Long, _
  14.         ByVal sServerName As String, _
  15.         ByVal nServerPort As Integer, _
  16.         ByVal sUsername As String, _
  17.         ByVal sPassword As String, _
  18.         ByVal lService As Long, _
  19.         ByVal lFlags As Long, _
  20.         ByVal lContext As Long) As Long

  21. 'Get a file using FTP
  22. Private Declare Function FtpGetFile _
  23.    Lib "wininet.dll" _
  24.      Alias "FtpGetFileA" _
  25.        (ByVal hFtpSession As Long, _
  26.         ByVal lpszRemoteFile As String, _
  27.         ByVal lpszNewFile As String, _
  28.         ByVal fFailIfExists As Boolean, _
  29.         ByVal dwFlagsAndAttributes As Long, _
  30.         ByVal dwFlags As Long, _
  31.         ByVal dwContext As Long) As Boolean

  32. 'Send a file using FTP
  33. Private Declare Function FtpPutFile _
  34.    Lib "wininet.dll" _
  35.      Alias "FtpPutFileA" _
  36.        (ByVal hFtpSession As Long, _
  37.         ByVal lpszLocalFile As String, _
  38.         ByVal lpszRemoteFile As String, _
  39.         ByVal dwFlags As Long, _
  40.         ByVal dwContext As Long) As Boolean

  41. 'Close the Internet object
  42. Private Declare Function InternetCloseHandle _
  43.    Lib "wininet.dll" _
  44.      (ByVal hInet As Long) As Integer

  45. Sub UploadFTP()

  46.   Dim INet As Long
  47.   Dim INetConn As Long
  48.   Dim hostFile As String
  49.   Dim Password As String
  50.   Dim RetVal As Long
  51.   Dim ServerName As String
  52.   Dim Success As Long
  53.   Dim UserName As String
  54.   
  55.   Const ASCII_TRANSFER = 1
  56.   Const BINARY_TRANSFER = 2

  57.     ServerName = "ftp://test.com"
  58.     UserName = "UserName"
  59.     Password = "Password"
  60.     localFile = "C:\a.csv"
  61.     hostFile = "\\a.csv"

  62.       RetVal = False
  63.       INet = InternetOpen("MyFTP Control", 1&, vbNullString, vbNullString, 0&)
  64.         If INet > 0 Then
  65.           INetConn = InternetConnect(INet, ServerName, 0&, UserName, Password, 1&, 0&, 0&)
  66.             If INetConn > 0 Then
  67.               Success = FtpPutFile(INetConn, localFile, hostFile, BINARY_TRANSFER, 0&)
  68.               RetVal = InternetCloseHandle(INetConn)
  69.             End If
  70.          RetVal = InternetCloseHandle(INet)
  71.         End If

  72.       If Success <> 0 Then
  73.         MsgBox ("Upload process completed")
  74.       Else
  75.         MsgBox "FTP File Error!"
  76.       End If

  77. End Sub
½Æ»s¥N½X
PKKO

³o¬O²Ä¤G­Ó½d¨Ò,¦ý¤]µLªk°õ¦æ,·Q½Ð±ÐÅܼƭn¦p¦ó¿é¤J
§Ú¥u·Q§âC:\a.csv ªºÀɮפW¶Ç¨ì"ftp://test.com" ªº¥Ø¿ý¤U­±¦Ó¤w
  1. Sub SaveToFTPSite()
  2. Dim ftpSite As String
  3. Dim UserID As String
  4. Dim UserPass As String
  5. Dim FTPPath As String
  6. Dim fPathFName As String
  7. Dim ftpWkb As Workbook
  8. ftpSite = "ftp://test.com"
  9. UserID = "UserID"
  10. UserPass = "UserPass"
  11. FTPPath = "upload"

  12. fPathFName = "C:\a.csv"

  13. Application.EnableEvents = False
  14. Application.DisplayAlerts = False

  15. Set ftpWkb = Workbooks.Open(fPathFName)
  16.    
  17. ActiveWorkbook.SaveAs Filename:="ftp://" & UserID & ":" & UserPass & "@" & ftpSite & "/" & FTPPath & "/" & ftpWkb.Name

  18. ftpWkb.Close

  19. Application.EnableEvents = True
  20. Application.DisplayAlerts = True
  21.         
  22. End Sub
½Æ»s¥N½X
PKKO

TOP

        ÀR«ä¦Û¦b : ¤H¨ÆªºÁ}Ãø»PµZ¿i¡A´N¬O¤@ºØ¦ÒÅç¡C
ªð¦^¦Cªí ¤W¤@¥DÃD