投稿‎ > ‎

VBA FTPGet

posted Jun 20, 2016, 12:13 AM by Zhang Wenxu
Public Sub FTPGet()
    Dim fromFile As String
    Dim toDir As String
    Dim fso As New FileSystemObject
    Dim cel As Range
    Dim localFile As String
    
    Set cel = ActiveCell
    fromFile = cel.value
    Set cel = cel.Offset(1, 1)
    toDir = "D:\work\data\" & Format(Now(), "yyyymmdd")
    Call createDir(toDir) 
    Call getByFTP(fromFile, toDir)
    localFile = toDir & "\" & fso.getFilename(fromFile)
    If Not fso.FileExists(localFile) Then
        Sleep 500
    End If
    cel.vallue = localFile
    Set cel = cel.Offset(1, 1)
    'Call readTextFile(localFile, cel)
End Sub

Private Function getByFTP(fromFile As String, toDir As String) As String
    Dim ret As String
    getByFTP = runCmd("java.exe -classpath commons-cli-1.0.jar;commons-io-1.4.jar;commons-net-3.3.jar; jp.btsol.ftp.FTPUtilsGet -f " & fromFile & " -d " & toDir & " -u username -p password -s XXX.XXX.XXX.XXX ")
    Debug.Print getByFTP
End Function

Comments