-
Notifications
You must be signed in to change notification settings - Fork 3
/
M_omFTP.def
66 lines (48 loc) · 1.89 KB
/
M_omFTP.def
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Option Compare Database
Option Explicit
Public Function UploadFile(ftpAddress As String, login As String, Password As String, fileName As String, Optional ftpPath As String = "/") As String
Dim outFilename As String
Dim ftpFilename As String
Dim batFilename As String
Dim lInt_FreeFile01 As Integer
Dim lInt_FreeFile02 As Integer
On Error GoTo Err_Handler
lInt_FreeFile01 = FreeFile
lInt_FreeFile02 = FreeFile
outFilename = fileName & ".out"
ftpFilename = fileName & ".ftp"
batFilename = fileName & ".bat"
'' Create text file with FTP commands
Open ftpFilename For Output As #lInt_FreeFile01
Print #lInt_FreeFile01, "open " & ftpAddress
Print #lInt_FreeFile01, login
Print #lInt_FreeFile01, Password
Print #lInt_FreeFile01, "cd " & ftpPath
Print #lInt_FreeFile01, "binary"
Print #lInt_FreeFile01, "send " & Chr(34) & fileName & Chr(34)
'' To receive a file, replace the above line with this one
''Print #lInt_FreeFile01, "recv \Picture.gif " & ThisWorkbook.Path & "\Picture.gif"
Print #lInt_FreeFile01, "bye"
Close #lInt_FreeFile01
'' Create Batch program
Open batFilename For Output As #lInt_FreeFile02
Print #lInt_FreeFile02, "ftp -s:" & Chr(34) & ftpFilename & Chr(34)
Print #lInt_FreeFile02, "Echo ""Complete"" > " & Chr(34) & outFilename & Chr(34)
Close #lInt_FreeFile02
'' Invoke Directory List generator
Shell (batFilename) ', vbHide '', vbMinimizedNoFocus
'Wait for completion
Do While Dir(outFilename) = ""
DoEvents
Loop
Sleep 3 * 1000
'' Clean up files
If Dir(batFilename) <> "" Then Kill (batFilename)
If Dir(outFilename) <> "" Then Kill (outFilename)
If Dir(ftpFilename) <> "" Then Kill (ftpFilename)
bye:
Exit Function
Err_Handler:
MsgBox "Error : " & Err.number & vbCrLf & "Description : " & Err.description, vbCritical
Resume bye
End Function